ICAP proxy integration (Beta)¶
Your forward proxy or secure web gateway can send AI traffic to MATVIS over ICAP (RFC 3507).
Prompts go through REQMOD and answers through RESPMOD, so the chat apps and API clients in
your network are screened without changing them.
ICAP is in beta: its behaviour can still change.
Turn ICAP on¶
ICAP is a second listener of the Firewall API, on port 1344, and it is off by default.
With Docker Compose, set it in .env and restart the stack:
With Helm, set it in values.yaml; with NodePort services the ICAP port is 31344:
Your proxy then uses two services:
| Service | URL |
|---|---|
| Prompts | icap://<matvis-host>:1344/reqmod |
| Answers | icap://<matvis-host>:1344/respmod |
OPTIONS advertises Allow: 204, Max-Connections: 100 and Options-TTL: 3600. MATVIS does not
support ICAP preview: send the whole message, since a verdict needs the whole prompt or answer.
It handles one transaction per connection and closes the connection after its answer. While the
ICAP headers arrive, the proxy may not pause more than 5 seconds; the body may pause up to 300
seconds between chunks.
Set the ICAP I/O timeout of your proxy above the time your models take to finish an answer:
MATVIS answers a RESPMOD only once the whole answer has arrived, streamed answers included.
Configure both services as bypass, so traffic still passes when MATVIS cannot be reached.
Configure the policy¶
In the dashboard, ICAP has its own configurations under Configuration → ICAP. Each one has three parts:
- Inbound and Outbound: the same filters as a firewall configuration,
applied to prompts (
REQMOD) and answers (RESPMOD). - AI Traffic Policy: what MATVIS does with traffic it recognises as an AI conversation.
The default for detected AI is one of:
- Content moderation: the conversation is screened with the Inbound and Outbound filters and blocked only on a real violation.
- Block on detection: the conversation is blocked as soon as it is recognised; its content is not read.
- Custom rules only: nothing happens by default; only the rules per host apply.
Rules per host override the default for one hostname: Trusted (never inspected, not logged), Content moderation (always screened, even if MATVIS does not recognise the host as AI), Block on detection, or Block whole host (all traffic to it is blocked). Listing a host is how you govern an AI service MATVIS does not recognise on its own.
Each request is inspected under one ICAP configuration. Name it in the ICAP request, with the
header X-ICAP-Config-Id: <config uuid> or the query ?config_id=<config uuid> on the ICAP URI.
Without one, or with an id that does not exist, the configuration marked Default applies (a
switch in the configuration; only one can be the default). When no configuration is the default,
such traffic passes unscanned. A named or default configuration that this MATVIS version cannot
read is refused: its traffic passes unscanned with X-MATVIS-Reason: config_refused:<id>, and no
other configuration is used in its place. MATVIS reads the
id only from the ICAP request, never from the end user's HTTP request. Send the same id on the
REQMOD and the RESPMOD of one HTTP transaction.
What MATVIS answers¶
| Outcome | ICAP answer |
|---|---|
| Allowed, unchanged | 200 with the original HTTP message; 204 for a message without a body |
| Allowed, changed (PII masked or restored) | 200 with the original HTTP head and the new body |
| Blocked | 200 carrying an HTTP 403 response for the end user |
An inspected message carries these headers:
X-MATVIS-Verdict:allow,block, orobserve(detected but not enforced, under monitoring mode).X-MATVIS-Reason: a short reason code, or-for a clean allow. Codes includeblocked_host:<host>,blocked_ai:<host>,content_too_large,masking_failedandconfig_refused:<id>.X-MATVIS-Scan: compact JSON with the verdict (result, the same object/api/v1/filter/inboundreturns) and a timestamp. It carries no message content. An answer forcontent_too_largeormasking_failedhas noX-MATVIS-Scan, since no scan ran.
X-MATVIS-Reason and the block_message inside X-MATVIS-Scan are cut at 256 characters. The
block page and the analytics event keep the whole message.
allow means MATVIS let the message through, not that it scanned it. Traffic that is not AI
traffic or is excluded (telemetry hosts, static files, health checks), a message with no text, a
scan that could not run and traffic under an inactive license all pass with allow as well. Your
proxy log cannot tell these apart from a clean scan, except a refused configuration, which carries
config_refused:<id>. A scanned message leaves a record in
Firewall analytics and in your SIEM, a message passed on without
a scan leaves none.
A blocked message gets an HTTP 403. On provider API paths (OpenAI /chat/completions and
/responses, Anthropic /v1/messages, Gemini :generateContent, Ollama /api/chat and others)
the body is the provider's error JSON with your configured block message, so SDKs show it as an API
error. On any other path the body is plain text, Access Denied followed by the block message. You
can deliver it as it is or show your own block page instead.
When MATVIS changes a body, Content-Length matches the new body (a head with
Transfer-Encoding keeps it and gets no Content-Length), and a body that arrived compressed goes
back uncompressed, without its Content-Encoding.
What MATVIS reads¶
MATVIS reads the prompts and answers of these services:
- APIs: OpenAI, Anthropic, Gemini, Ollama and OpenAI-compatible APIs.
- Web apps: ChatGPT, Claude, Gemini, DeepSeek, Qwen, Kimi, Perplexity, Mistral Le Chat, Grok, Pi, Google AI Mode, OpenRouter Chatroom and Telekom Frag Magenta.
Other AI services are read on a best-effort basis.
How a request is scanned¶
A request to one of the APIs carries the whole conversation on every turn, because the client writes the whole request. MATVIS scans it message by message, in order:
- Every message goes through the Inbound filters: the system prompt, the user's messages, tool results and the assistant's earlier messages.
- Each message is one scan and one event in Firewall analytics.
- The first message that blocks answers the request. Otherwise the first message flagged under
monitoring mode answers
observe. - In Full Retention, messages scanned on an earlier turn are served from the message cache, so a long conversation costs no more filter time than its new message. Any change to the configuration starts a fresh cache.
The web apps send only the new message, which is one scan, and an answer is one scan.
What ICAP cannot see¶
Your proxy must decrypt TLS for MATVIS to read content. Two kinds of traffic are not visible over ICAP:
- Services that pin their certificates.
- Traffic over WebSockets (Microsoft Copilot, Microsoft 365 Copilot, Meta AI, Character.ai, Poe, some ChatGPT and Grok sessions).
Govern them by host in the AI Traffic Policy.
Size limit¶
MATVIS scans up to 1,000,000 UTF-8 bytes of extracted text per message: the prompt or answer text,
not the HTTP body. Images and attachments do not count and are not inspected. A larger message is
blocked with X-MATVIS-Reason: content_too_large, or passes with observe under monitoring mode.
PII masking and restore¶
With Pseudonymization on in the Inbound section, the personal data MATVIS finds in a prompt is
replaced by tokens (PERSON_<digest>, EMAIL_<digest>, ...) in the request your proxy forwards:
in every string of a JSON body or every field of a URL-encoded form, earlier messages of the
conversation included. Google AI Mode sends the prompt in the URL, so there the query values of the
URL and of the Referer are masked.
The mapping from tokens back to the original values travels in a header:
- The
REQMODanswer carries it in the headerX-MATVIS-PII-Mapping. - Your proxy keeps it and sends it back, unchanged, as an ICAP request header on the
RESPMODof the same HTTP transaction. - With De-pseudonymization on in the Outbound section, MATVIS then puts the original values back into the answer before it reaches the user, streamed or not, tool-call arguments included. Every streamed event stays in place.
- To restore the values yourself, decode the header and do not send it back.
| Section | Setting |
|---|---|
| Inbound | PII filter on with the entity types to mask, Pseudonymization on |
| Outbound | PII filter on, De-pseudonymization on, no PII entity types |
The answer is restored first and then scanned: with PII entity types on in the Outbound section too, a restored value can block the answer. Leave them off unless you want that.
The header is sent only when at least one value was masked, never on a blocked request. Its value is:
- base64url without padding (RFC 4648, section 5),
- of a compact UTF-8 JSON object,
- with one entry per token in the forwarded body, in the same shape as
filters.PII.details.mappingof/api/v1/filter/inbound:
A token is the entity prefix and ten characters of Crockford base32, a digest of the value keyed with your deployment's pseudonymization secret.
- The same value of the same type gets the same token within a deployment.
- Without the secret, a token cannot be reversed or matched against a guess.
- Tokens are matched in any letter case on the way back. A token whose underscore the model
escaped for markdown (
EMAIL\_...) is still restored. - The header has no fixed size limit, so size the header limits of your proxy for prompts with many values. MATVIS never truncates it.
- A value MATVIS cannot decode is ignored, and the answer is scanned and delivered without restore.
The mapping header holds personal data in clear text
Do not write X-MATVIS-PII-Mapping to access logs or send it anywhere but back to MATVIS.
Send it only as an ICAP request header on the RESPMOD; MATVIS ignores it inside the HTTP
request or response.
A prompt is passed on unmasked, without the header, when the body is neither JSON nor a URL-encoded
form (outside Google AI Mode), when the destination signs or checks its request body (AWS Bedrock),
or when a detected value does not occur in the body exactly as detected; the event in Firewall
analytics reports the PII as detected but not masked. MATVIS keeps nothing between REQMOD and
RESPMOD, so without the header coming back nothing is restored. Web chats that store the
conversation at the provider show tokens in reloaded history, and a token the model changes
(separator, truncation, characters) is not restored.
Tracing and metrics¶
Send a W3C traceparent header as an ICAP request header and MATVIS continues that trace: each
transaction is one span (ICAP REQMOD, ICAP RESPMOD), a child of your proxy's span, and the
syslog and Splunk HEC events of the transaction carry its trace ID. Without one in the ICAP request,
MATVIS uses a traceparent from the HTTP request, or starts a new trace.
The span carries no content: the ICAP method, service and status code (icap.method,
icap.service, icap.status_code), the direction (matvis.direction), the configuration
(matvis.icap.config_id), the HTTP host (server.address), the verdict (matvis.verdict: allow,
observe, block, pass when nothing was scanned, or refused when the configuration was
refused) and block reason (matvis.block_reason), the
number of messages scanned (matvis.icap.units) and the body size (matvis.icap.body_bytes). It is
marked failed when a scan could not run, the request could not be parsed, MATVIS answered 500, or
the body read timed out; a block is not a failure.
The Firewall API's /prometheus endpoint counts ICAP traffic: icap_requests_total{method,status_code,verdict},
icap_request_duration_seconds{method} and icap_requests_in_flight. The verdict label takes the
same values as matvis.verdict, plus none when no verdict was reached (OPTIONS, an error
answer, no answer). status_code is 0 when no answer was sent.
When masking fails¶
When masking is asked for but cannot be done safely, the request is blocked with an HTTP 403 and
X-MATVIS-Reason: masking_failed, even under monitoring mode. Passing it on would send the
unmasked values.
Example: Squid¶
These directives route traffic through MATVIS and carry the mapping header from REQMOD to
RESPMOD:
icap_enable on
icap_preview_enable off
icap_send_client_ip on
icap_send_client_username on
icap_io_timeout 300 seconds
adaptation_masterx_shared_names X-MATVIS-PII-Mapping
icap_service service_req reqmod_precache bypass=1 icap://<matvis-host>:1344/reqmod
icap_service service_resp respmod_precache bypass=1 icap://<matvis-host>:1344/respmod
adaptation_access service_req allow all
adaptation_access service_resp allow all