For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Response header sanitization
Remove every response header that is not on an allowlist, so that only approved headers reach the client.
Response header sanitization in Solo Enterprise for kgateway removes every response header that you do not explicitly permit. You list the headers that clients might receive, and the gateway strips the rest before the response leaves for the client.
Sanitization makes the gateway the enforcement point for response headers. When a backend service starts to return a new internal header, the gateway removes that header without anybody having to spot the change first.
Important
Response header sanitization requires Solo Enterprise for kgateway version 2.3.3 or later.
About response header sanitization
Solo Enterprise for kgateway gives you four ways to control response headers, and each one follows one of two opposite models. A deny list removes the headers that you name, and every header that you do not name passes through. An allowlist does the reverse, and keeps only the headers that you name. Sanitization is the only mechanism that uses an allowlist.
| Resource | Field to configure | Description | Model | Behavior |
|---|---|---|---|---|
HTTPRoute | filters.responseHeaderModifier.remove | Remove a header from a response with a route filter. | Deny list | Removes the headers that you name. |
EnterpriseKgatewayTrafficPolicy | headerModifiers.response.remove | Remove a header from a response with a policy instead of a route filter. | Deny list | Removes the headers that you name. |
EnterpriseKgatewayTrafficPolicy | entTransformation | Remove or set a header, with templating and a choice of three stages. | Deny list | Removes or sets the headers that you name. |
EnterpriseKgatewayTrafficPolicy | entHeaderSanitization | Permit an approved set of headers, and remove every other header. | Allowlist | Removes every header that you do not name. |
A deny list grows with each backend service, and it protects you only against the headers that somebody already thought of. An allowlist inverts that, so the gateway removes a header that a backend adds later.
Sanitization itself offers the allowlist model only. The entHeaderSanitization field takes no deny list, so to remove named headers and let the rest through, use one of the deny-list mechanisms in the preceding table. You can apply both kinds of policy to the same route, because they are separate features.
Two things follow from sanitization being its own field rather than another entTransformation stage. First, sanitization takes any filter stage, so you choose which other filters see a header before the gateway removes it. The entTransformation field offers three fixed stages instead. Second, the gateway merges each field on its own, so a policy that changes headers through entTransformation cannot override your allowlist, whatever resource that policy targets.
Note
Sanitization applies to response headers only. It does not affect request headers, response trailers, or response bodies. For the full scope, see What sanitization does not affect.
Configuration overview
To configure sanitization, add an entHeaderSanitization section to an EnterpriseKgatewayTrafficPolicy. Then, target the policy at a Gateway, a ListenerSet, or an HTTPRoute. To sanitize a single listener of a Gateway instead of every listener, add the listener’s name in the sectionName field of the target reference. The following example shows every supported field.
entHeaderSanitization:
response:
allowlist:
- x-app-version
- x-trace-id
filterStage:
stage: Route
predicate: After
weight: 0| Field | Description |
|---|---|
response | Required. Rules for the response path. This field is the only direction that sanitization supports today, and the API server rejects a policy that omits this field. |
response.allowlist | Required, and can be empty. The list of non-critical header names that clients are allowed to receive. Matching is case-insensitive, so X-App-Version and x-app-version are equivalent. The list holds a maximum of 256 entries, and each name is 1 to 256 characters from the HTTP header token set. Because a colon is not a token character, you cannot list a pseudo-header such as :status, which the gateway always keeps anyway. To remove every header that is not one of the built-in critical headers, set an empty list, allowlist: []. Omitting the field entirely is not the same thing, and the API server rejects such a policy. |
response.filterStage | Optional. Where in the Envoy HTTP filter chain sanitization runs. Omit this field to sanitize as the last step before the response reaches the client. See Change where sanitization runs in the filter chain. |
response.filterStage.stage | Required if you set filterStage. One of Fault, AuthN, AuthZ, RateLimit, or Route. |
response.filterStage.predicate | Optional. Where sanitization runs in relation to the other filters at the same stage. One of Before, During, or After. Defaults to During. Note that this default applies only when you set filterStage and omit predicate. When you omit filterStage entirely, the stage defaults to {stage: Fault, predicate: Before} instead. |
response.filterStage.weight | Optional. The stage and the predicate decide where sanitization sits in the chain, and weight only orders sanitization against another sanitization filter that landed in the same place. A higher weight runs earlier in the chain, which on the response path means running later. Defaults to 0. Note that 0 is a baseline rather than the front of the chain, because negative weights are valid and a higher weight wins. A single sanitization policy has nothing to tie against, so the default changes nothing, and even two sanitizers in series intersect their allowlists whichever order they run in. Weight is also part of the filter’s identity, so two policies that share a stage and a predicate but differ in weight produce two filters instead of one merged filter. See How two policies combine. |
Important
The allowlist matches complete header names only, and supports no wildcards or prefixes. List each header that your clients need, in full.
Note that an entry such as x-envoy-* does not fail validation, because an asterisk is a legal character in an HTTP header name. The entry does not act as a wildcard either. The gateway compares header names for exact equality, so the entry permits a header named x-envoy-* literally and nothing else. Your real x-envoy- headers are then removed for the ordinary reason, which is that no allowlist entry names them, so the entry achieves the same result as writing nothing at all.
Headers that sanitization cannot remove
Sanitization does not remove the following critical headers to prevent malformed responses. Separately, Envoy adds a few headers after the HTTP filter chain finishes, which puts them out of reach of any allowlist. Moving sanitization to a different filter stage does not catch either group, although what you can do about a header differs between the two.
| Header | Why sanitization cannot remove the header | What to do |
|---|---|---|
Framing and body: content-encoding, content-length, content-range, content-type, trailer, transfer-encoding, vary | Built-in critical list. | Nothing. This list cannot be configured. |
Connection: connection, keep-alive, proxy-connection, upgrade | Built-in critical list. | Nothing. This list cannot be configured. |
Protocol correctness: accept-ranges, allow, location, proxy-authenticate, retry-after, www-authenticate | Built-in critical list. | Nothing. This list cannot be configured. |
Caching: age, cache-control, etag, expires, last-modified, pragma | Built-in critical list. | Nothing. This list cannot be configured. |
Pseudo-headers: every header name that starts with a colon, such as :status | Built-in critical list. A colon is not a legal character in an allowlist entry either. | Nothing. This list cannot be configured. |
date | The date header belongs to the built-in critical list. If no date header is present, Envoy adds the header before the response is returned. | Nothing. You cannot configure the date header. |
server | Envoy sets the header after the filter chain finishes, overwriting whatever value the chain produced. | Set httpSettings.serverHeaderTransformation and httpSettings.serverName on a ListenerPolicy to remove this header. |
x-request-id | Envoy copies the request ID into the response after the filter chain finishes, and only when the client sends the x-envoy-force-trace request header to ask for it. Envoy honors that request header on internal requests only. | Nothing on the gateway. Envoy reads x-envoy-force-trace before any filter runs, so removing the header with a request header modifier comes too late, and sanitization cannot reach the response header either. An external client cannot make x-request-id appear, so the header shows up only when an internal client asks for it. Stop your internal clients from sending x-envoy-force-trace to keep the header out of responses. |
via, proxy-status | Envoy can add these headers after the filter chain, but only when configured to. Solo Enterprise for kgateway exposes no field to turn on either option, so neither header ever appears in a response. | Nothing. There is no field to configure. |
Headers that are removed by default
Sanitization removes the following three groups of headers by default as they do not impact the protocol correctness of a response. You can allowlist these headers if you want to keep them. Because the allowlist takes no prefixes, name each header of a group that you want to keep.
| Headers | What sanitization does | What to do |
|---|---|---|
set-cookie | Removes set-cookie. Cookies carry app data, and stripping them is a legitimate thing to want, so the choice belongs to you. | Allowlist set-cookie if your clients need cookies. |
The Envoy diagnostic headers, whose names start with x-envoy- | The router adds headers such as x-envoy-upstream-service-time, x-envoy-attempt-count, x-envoy-overloaded, x-envoy-degraded, and x-envoy-ratelimited, and sanitization removes every one of them at the default stage. For the full set that Envoy can add, and the condition for each one, see the Envoy HTTP header documentation. | Allowlist the full name of each one that your clients use for debugging, such as x-envoy-upstream-service-time. |
The Cross-Origin Resource Sharing (CORS) headers, whose names start with access-control- | Removes the CORS headers whatever their source. A backend can set them itself, but most deployments rely on the Envoy CORS filter to add them instead, based on a configured CORS policy. Headers that the CORS filter adds are subject to the allowlist at the default stage, but not at {stage: Route, predicate: After}, where sanitization runs before the CORS filter. The CORS filter can add access-control-allow-origin, access-control-allow-credentials, access-control-expose-headers, access-control-allow-methods, access-control-allow-headers, and access-control-max-age. For what each one does, see CORS. | Allowlist the full name of each one that your clients need to enforce CORS, such as access-control-allow-origin. |
What sanitization does not affect
Sanitization affects response headers only. For these other items, review what to use instead.
| Not affected | What to use instead |
|---|---|
| Request headers | Sanitization runs on the response path only. Use headerModifiers.request or entTransformation to control request headers. |
| Response trailers | Trailers pass through untouched, and sanitization neither counts nor logs them. A value that a backend sends as a trailer reaches the client whatever the allowlist says. Trailers are available on HTTP/2 and HTTP/3, and on HTTP/1.1 with chunked transfer encoding. Note that gRPC backends always send trailers for grpc-status and grpc-message. |
| Response bodies | To mask sensitive data in a body, see Data loss prevention (DLP). |
| The router’s upstream filter chain | Envoy runs two chains. Sanitization runs in the HTTP connection manager chain, and the filterStage field decides which filters in that chain see a header before sanitization removes it. The router’s upstream chain sits past the end of that chain, closer to the backend, and an external processing (ExtProc) filter whose own stage is after route runs there. No filter stage moves sanitization into the upstream chain, so filters in the upstream chain always see the full, unsanitized header set. |
Before you begin
Follow the Get started guide to install Solo Enterprise for kgateway.
Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n kgateway-system http -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo $INGRESS_GW_ADDRESSkubectl port-forward deployment/http -n kgateway-system 8080:8080
Sanitize response headers with an allowlist
In this section, you permit one application header through and verify that the gateway removes all other non-critical headers from the response. The httpbin /response-headers endpoint returns each query parameter as a response header, which lets you simulate a backend that returns internal headers so that you can test the removal of non-critical headers.
Send a request to the httpbin app with the
x-secret,x-app-version, andx-backend-hostquery parameters. Verify that you get back a 200 HTTP response and that the response includes the 3 query parameters as headers.curl -i "http://$INGRESS_GW_ADDRESS:8080/response-headers?x-secret=leak&x-app-version=1.2.3&x-backend-host=internal-svc-7" \ -H "host: www.example.com:8080"curl -i "localhost:8080/response-headers?x-secret=leak&x-app-version=1.2.3&x-backend-host=internal-svc-7" \ -H "host: www.example.com"Example output:
HTTP/1.1 200 OK access-control-allow-credentials: true access-control-allow-origin: * content-type: application/json; encoding=utf-8 x-app-version: 1.2.3 x-backend-host: internal-svc-7 x-secret: leak date: Wed, 02 Sep 2026 15:09:11 GMT content-length: 121 x-envoy-upstream-service-time: 1 server: envoyCreate an
EnterpriseKgatewayTrafficPolicythat targets your HTTPRoute and permits only thex-app-versionheader. This example lists the name in mixed case to show that matching is case-insensitive.kubectl apply -f- <<EOF apiVersion: enterprisekgateway.solo.io/v1alpha1 kind: EnterpriseKgatewayTrafficPolicy metadata: name: header-sanitization namespace: httpbin spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: httpbin entHeaderSanitization: response: allowlist: - X-App-Version EOFSend the same request again. Verify that
x-app-versionstill arrives, and that thex-secretandx-backend-hostheaders are removed.curl -i "http://$INGRESS_GW_ADDRESS:8080/response-headers?x-secret=leak&x-app-version=1.2.3&x-backend-host=internal-svc-7" \ -H "host: www.example.com:8080"curl -i "localhost:8080/response-headers?x-secret=leak&x-app-version=1.2.3&x-backend-host=internal-svc-7" \ -H "host: www.example.com"Example output. Your policy names only
x-app-version, and an allowlist removes every non-critical header that you do not name, so the gateway removed thex-secretandx-backend-hostheaders that the backend returned. The gateway also removed theaccess-control-allow-credentials,access-control-allow-origin, andx-envoy-upstream-service-timeheaders, which were added by Envoy during the response processing. Sanitization runs at the default stage here, which is last on the response path, so it sees those headers and treats them like any other header that the allowlist does not name. Thecontent-type,content-length,date, andserverheaders remain because sanitization cannot remove them whatever the allowlist says.HTTP/1.1 200 OK content-type: application/json; encoding=utf-8 x-app-version: 1.2.3 date: Wed, 02 Sep 2026 15:09:26 GMT content-length: 121 server: envoy
Strip all non-critical response headers
An empty allowlist is a valid configuration that removes every header except the built-in critical ones. Use an empty allowlist when your clients do not need app-specific headers at all.
Update your policy to use an empty allowlist.
kubectl patch enterprisekgatewaytrafficpolicy header-sanitization -n httpbin --type=merge \ -p '{"spec":{"entHeaderSanitization":{"response":{"allowlist":[]}}}}'Send a request and verify that even
x-app-versionis now removed.curl -i "http://$INGRESS_GW_ADDRESS:8080/response-headers?x-secret=leak&x-app-version=1.2.3" \ -H "host: www.example.com:8080"curl -i "localhost:8080/response-headers?x-secret=leak&x-app-version=1.2.3" \ -H "host: www.example.com"Example output:
HTTP/1.1 200 OK content-type: application/json; encoding=utf-8 date: Wed, 02 Sep 2026 14:59:16 GMT content-length: 73 server: envoy
Change where sanitization runs in the filter chain
Envoy builds one filter chain and runs the response back through it in reverse. The filterStage field names a position in that chain, so the further toward the backend you place sanitization, the earlier it runs on the response path, and the fewer filters see the headers before sanitization removes them.
The stage and predicate values give you a range of positions, and the following table describes the two ends of that range. Every other combination of a stage from Fault, AuthN, AuthZ, RateLimit, or Route with a predicate of Before, During, or After lands somewhere between them.
filterStage | Where sanitization sits | Order on the response path | Which filters see the headers that will be removed |
|---|---|---|---|
Omitted, which is {stage: Fault, predicate: Before} | The client end of the chain | Sanitizes last, immediately before the response goes to the client | Every other filter in the chain. Only the client does not see them. |
{stage: Route, predicate: After} | The backend end of the chain | Sanitizes first, immediately after the response leaves the router | No filter in the chain, and neither does the client. |
| Any other stage and predicate | Between those two ends | Sanitizes partway through | Only the filters that sanitization runs after, which are the ones nearer the backend. |
Before and After are absolute within a stage. Before places sanitization ahead of every other filter at that stage, and After places it behind every one of them. So {stage: Route, predicate: After} also runs behind entTransformation’s postRouting stage, even though both resolve to the Route stage. On the response path, that means sanitization runs before a postRouting transformation and cannot see the headers that the transformation sets.
In this section, you add a transformation that sets a marker header on the response, and then move sanitization to each end of the chain to see which placement removes the marker.
Create a second policy that adds an
x-probeheader to the response at the regular transformation stage.kubectl apply -f- <<EOF apiVersion: enterprisekgateway.solo.io/v1alpha1 kind: EnterpriseKgatewayTrafficPolicy metadata: name: header-sanitization-probe namespace: httpbin spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: httpbin entTransformation: stages: regular: responses: - transformation: template: headers: x-probe: 'set-by-transformation' EOFRestore the allowlist to permit
x-app-version, and leavefilterStageout so that sanitization runs at the default stage.kubectl patch enterprisekgatewaytrafficpolicy header-sanitization -n httpbin --type=merge \ -p '{"spec":{"entHeaderSanitization":{"response":{"allowlist":["x-app-version"]}}}}'Send a request. Verify that
x-probedoes not reach the client, because sanitization runs after the transformation on the response path.curl -i "http://$INGRESS_GW_ADDRESS:8080/response-headers?x-app-version=1.2.3" \ -H "host: www.example.com:8080"curl -i "localhost:8080/response-headers?x-app-version=1.2.3" \ -H "host: www.example.com"Example output:
HTTP/1.1 200 OK content-type: application/json; encoding=utf-8 x-app-version: 1.2.3 date: Wed, 02 Sep 2026 15:15:04 GMT content-length: 41 server: envoyMove sanitization to the backend end of the chain,
{stage: Route, predicate: After}, so that it runs first on the response path.kubectl patch enterprisekgatewaytrafficpolicy header-sanitization -n httpbin --type=merge \ -p '{"spec":{"entHeaderSanitization":{"response":{"allowlist":["x-app-version"],"filterStage":{"stage":"Route","predicate":"After"}}}}}'Send the request again. Verify that
x-probenow reaches the client, because sanitization runs before the transformation on the response path and cannot see a header that does not exist yet.curl -i "http://$INGRESS_GW_ADDRESS:8080/response-headers?x-app-version=1.2.3" \ -H "host: www.example.com:8080"curl -i "localhost:8080/response-headers?x-app-version=1.2.3" \ -H "host: www.example.com"Example output:
HTTP/1.1 200 OK content-type: application/json; encoding=utf-8 x-app-version: 1.2.3 date: Wed, 02 Sep 2026 15:15:09 GMT content-length: 41 x-probe: set-by-transformation server: envoy
How two policies combine
When two sanitization policies apply to the same route, the result depends on whether they sit at the same level of the policy hierarchy. For the hierarchy itself and the annotation that controls it, see Policy merging.
Two policies at the same level, such as two EnterpriseKgatewayTrafficPolicy resources that both target the same HTTPRoute, are deep merged by default. What that produces depends on the stage that each one resolves to.
| Stages | Result |
|---|---|
| The same stage, predicate, and weight | The gateway combines both allowlists into a single filter. The merged allowlist is the union of the two, and a union does not depend on order, so neither policy takes precedence. Merging this way widens the allowlist rather than narrowing it, so one policy cannot restrict what another permits. |
| Any difference in stage, predicate, or weight | Each policy becomes its own filter, and the response passes through both. Sanitizers in series intersect, so the client sees only the headers that every policy permits. |
A policy on a Gateway or a ListenerSet and a policy on a route beneath it are not merged at all. Each one configures sanitization at its own level of the Envoy config, and Envoy applies the most specific configuration it finds, so the route policy’s allowlist replaces the Gateway policy’s. Setting the kgateway.dev/inherited-policy-priority annotation on the Gateway does not change this behavior.
To force strict override behavior between two policies at the same level, set policyMerge.enterpriseKgatewayTrafficPolicy.entHeaderSanitization to ShallowMerge in your Helm values.
Monitor the headers that sanitization removes
Sanitization reports its work in two ways. Counters tell you how much the gateway removes, and dynamic metadata names the exact headers that the gateway removed from each response.
Port-forward port 19000 of the gateway proxy, which serves the counters.
kubectl port-forward deployment/http -n kgateway-system 19000:19000Check the sanitization counters. Note that the counters carry a
dynamicmodulescustom.prefix, because sanitization runs as an Envoy dynamic module.curl -s "localhost:19000/stats?filter=header_sanitization"Example output:
dynamicmodulescustom.solo.io.http.header_sanitization.removed: 25 dynamicmodulescustom.solo.io.http.header_sanitization.responses_sanitized: 5Counter Description dynamicmodulescustom.solo.io.http.header_sanitization.removedThe number of distinct response header names removed. This counter counts header names, not header lines, so a header that a backend sends three times counts once. dynamicmodulescustom.solo.io.http.header_sanitization.responses_sanitizedThe number of responses that had at least one header removed. The gateway counts a response once even when several stages remove headers from it. Both counters are running totals for the lifetime of the gateway proxy, so the values only climb, and they reset when the proxy restarts. To see the headers that a single response lost, use the access log in the following steps instead.
To record which headers the gateway removed, create a
ListenerPolicythat writes the sanitization metadata to the access log. Sanitization appends each removed header name to theremoved_response_headerskey in theio.solo.http.header_sanitizationnamespace. Note that this metadata namespace carries nodynamicmodulescustom.prefix, unlike the counters.kubectl apply -f- <<EOF apiVersion: gateway.kgateway.dev/v1alpha1 kind: ListenerPolicy metadata: name: header-sanitization-access-logs namespace: kgateway-system spec: targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: http default: httpSettings: accessLog: - fileSink: path: /dev/stdout jsonFormat: path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%" response_code: "%RESPONSE_CODE%" removed_response_headers: "%DYNAMIC_METADATA(io.solo.http.header_sanitization:removed_response_headers)%" EOFSend a request, and then check the gateway proxy logs. Verify that the log entry records the removed header names.
curl -i "http://$INGRESS_GW_ADDRESS:8080/response-headers?x-secret=leak&x-backend-host=internal-svc-7&x-app-version=1.2.3" \ -H "host: www.example.com:8080"curl -i "localhost:8080/response-headers?x-secret=leak&x-backend-host=internal-svc-7&x-app-version=1.2.3" \ -H "host: www.example.com"kubectl logs -n kgateway-system deployment/http | grep removed_response_headers | tail -1Example output:
{"path":"/response-headers?x-secret=leak&x-backend-host=internal-svc-7&x-app-version=1.2.3","removed_response_headers":["access-control-allow-credentials","access-control-allow-origin","x-backend-host","x-secret","x-envoy-upstream-service-time"],"response_code":200}The access logs only show the header names that were removed, not the header values. If no headers were removed in a response, no sanitization data is included in your access log.
Cleanup
You can optionally remove the resources that you set up as part of this guide.kubectl delete listenerpolicy -n kgateway-system header-sanitization-access-logs --ignore-not-found
kubectl delete enterprisekgatewaytrafficpolicy -n httpbin header-sanitization-probe --ignore-not-found
kubectl delete enterprisekgatewaytrafficpolicy -n httpbin header-sanitization