Zero-trust forwarding: what the backend receives¶
How-to guideThe steps for one task.
By default the gateway forwards what the client sent, minus the credentials it validated and
the identity headers it sets itself. A backend therefore also receives the client's cookies, its
User-Agent, any X-Debug header a developer left in, and every tracking parameter a link
carried. The forward policy turns that around: the backend receives only the headers and
query parameters you list, plus what the gateway and your own policies set.
apiVersion: apinx/v1
kind: API
name: orders
base_path: /orders
upstream: orders-service
strip_prefix: true
policies:
- type: api-key
- type: forward
config:
headers: [Accept, Accept-Language, If-None-Match, X-Request-Id]
query: [page, size, sort]
operations:
- name: list
path: /
methods: [GET]
Before and after¶
A client sends:
GET /orders?page=2&utm_source=mail HTTP/1.1
Host: api.example.com
X-API-Key: apk_…
Accept: application/json
Accept-Language: en
User-Agent: curl/8.6
Cookie: session=…
X-Debug: 1
X-Apinx-Application: forged
What the orders service receives:
| Header or parameter | Without forward |
With the policy above |
|---|---|---|
X-API-Key |
Removed by api-key |
Removed by api-key |
Accept, Accept-Language |
Yes | Yes, listed |
User-Agent, Cookie, X-Debug |
Yes | Dropped |
X-Apinx-Application: forged |
Removed, then set by api-key to the real application |
The same |
X-Apinx-Application-Id, X-Apinx-Subject, X-Apinx-Auth |
Set by api-key |
Set by api-key |
Via: 1.1 apinx, X-Forwarded-For, X-Forwarded-Host, X-Forwarded-Proto |
Set by the gateway | Set by the gateway |
?page=2 |
Yes | Yes, listed |
?utm_source=mail |
Yes | Dropped |
Nothing about the body changes: Content-Type, Content-Length, Content-Encoding and
Transfer-Encoding always pass, as do the connection headers (Connection, Upgrade, TE,
Trailer, Expect).
What always passes¶
- The body and connection headers above; without them the request would be unreadable.
Viaand theX-Forwarded-*headers the gateway sets.- Every
X-Apinx-*header: the gateway's identity headers are set by the authentication policies after a client's own values were removed, so a client cannot claim an identity whether the policy is bound or not. - Anything a
transform,set-header,upstream-authorservice-calloutpolicy sets.
Dropped only where the value is still the client's¶
The policy runs early, in the access phase, and remembers what the client sent under every name that is not listed. The dropping happens at the last moment, right before the backend is called, and only where the header or parameter still carries the client's value. Two things follow:
- Authentication reads first.
AuthorizationandX-API-Keyneed not be listed forapi-key,jwtorbasicto see them; they are stripped by those policies anyway once validated. A backend that must receive the caller's token (jwtwithstrip: false) does needAuthorizationin the list, or the token is dropped as a client header. - A value set by a later policy reaches the backend, even under a name the client used:
policies:
- type: forward
config:
headers: [Accept]
- type: transform
config:
request:
headers:
set: { X-Debug: "route ${route}" }
The client's X-Debug: 1 is not listed, but by dispatch time the header holds route
orders-list, not the client's value, so it is forwarded. Had the transform set it to exactly
1, the policy could not tell the two apart and would drop it.
The request inspector shows the decision as a dispatch step of the policy: dropped headers:
Cookie, User-Agent, X-Debug; dropped query: utm_source, or nothing to drop.
The lists¶
| Setting | Meaning |
|---|---|
headers |
Client headers the backend may receive, by name; case does not matter. Left out or empty: no client header passes. ["*"]: all. |
query |
Query parameters the backend may receive, by name (case matters). Left out: every parameter passes, since the query is usually part of the API's contract. []: none. ["*"]: all. |
Bind the policy on the API for one list every operation shares, and override it on an
operation that needs more (strategy: override) or add names to the inherited list with
strategy: merge.
A minimal list for a JSON API¶
- type: forward
config:
headers:
- Accept
- Accept-Language
- If-None-Match # conditional GETs keep working
- If-Modified-Since
- X-Request-Id # the caller's correlation id, if you honour one
- Idempotency-Key # for APIs that de-duplicate writes
query: [page, size, sort, filter] # the API's own parameters
Add Authorization only when the backend must see the caller's token, and Accept-Encoding
only when the backend should compress its answers itself. Leave User-Agent, Cookie,
Referer and Origin out unless the backend reads them; a CORS check belongs in the cors
policy, not in the backend.
Audit¶
apinx gateway audit and the Overview's Configuration findings report an operation that
runs no forward policy as headers-forwarded-unfiltered (low), so a gateway where every API
has a list stays silent. The command line has the rules.
Cost¶
A route without the policy pays nothing. With it, one pass over the request's headers and query when the policy runs and one at dispatch; no allocation beyond the names remembered.