← Blog
December 3, 202610 min readAppSecSecurity EngineeringVulnerability ResearchAuthentication

Six kinds of request header your edge should never pass through untouched

X-Original-URL, X-Forwarded-For, X-Forwarded-Host, method overrides, auth-proxy identity headers and framework control headers all carry trust only if your edge wrote them. What each family controls, the real bugs behind them, how strip lists fail, and an nginx snippet.

By The Xalgorix Team

GET / HTTP/1.1
Host: shop.example
X-Original-URL: /admin

The front end sees a request for /, checks it against its rules, and forwards it. The application framework reads X-Original-URL, decides the real path is /admin, and serves the admin panel the front end was configured to block. That is the whole of PortSwigger's “URL-based access control can be circumvented” lab, and it is the same shape as a long list of real bugs: a component behind the edge trusts a header that it assumes the edge wrote, and the edge forwards whatever the client sent.

Headers like this are messages between your own infrastructure components. They only carry meaning if an outsider cannot write them. Most stacks have several, spread across the framework, the auth proxy and the load balancer, and nobody owns the full list. Below are six families worth inventorying, what each one controls, the primary sources behind them, and the ways a strip list fails even after you write one.

One rule decides whether a header can be trusted

A request header is trustworthy for a security decision only when two things hold: the last hop you control set it (overwrote or removed whatever the client sent), and nothing can reach the consuming component without passing through that hop. Break either and the header is attacker input with an official-sounding name.

Client
writes any header it likes
Edge proxy / CDN
strips or overwrites
Auth proxy
adds identity headers
Application
reads them as facts
The edge is the only place that can tell client-written headers from ones your infrastructure wrote. Every component behind it inherits that decision.

MDN puts the second condition bluntly in its X-Forwarded-For reference: if the server “can be directly connected to from the internet — even if it is also behind a trusted reverse proxy — no part of the X-Forwarded-For IP list can be considered trustworthy or safe for security-related uses.” The same reasoning applies to every family below.

1. Client IP: X-Forwarded-For, X-Real-IP, True-Client-IP

Rate limiters, IP allowlists for admin panels, geo rules, fraud scoring and audit logs all want the client's address, and behind a proxy the socket address is the proxy's. So the app reads a header. MDN lists the consequences of reading the wrong part of it: “rate-limiter avoidance, access-control bypass, memory exhaustion”.

The trap is that X-Forwarded-For is a list that proxies append to, so the leftmost entries are whatever the client sent. nginx's $proxy_add_x_forwarded_for is documented as the client's header “with the $remote_addr variable appended to it”, which is correct for an internal hop and wrong for the internet-facing one. Express makes the same point from the application side. Its behind-proxies guide says that with trust proxy set to true, “the client's IP address is understood as the left-most entry in the X-Forwarded-For header”, and warns that the last trusted proxy must then remove or overwrite X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto, “otherwise it may be possible for the client to provide any value.”

// Express: trust only the hops you actually run
app.set("trust proxy", "loopback, 10.0.0.0/8"); // your LB's subnet
// or, if there is exactly one proxy in front:
app.set("trust proxy", 1);

// Avoid: app.set("trust proxy", true)  -> req.ip = leftmost, client-controlled

The hop-count form has its own caveat in the same guide: it is only safe if there are no “multiple, different-length paths to the Express application”. A second ingress that skips the CDN quietly shifts every index by one. On nginx, the realip module does the equivalent job: set_real_ip_from names the addresses “known to send correct replacement addresses” (your CDN's ranges), and with real_ip_recursive on the client address becomes “the last non-trusted address” in the header rather than the first one.

2. Host overrides: X-Forwarded-Host and its siblings

Applications build absolute URLs constantly: password-reset links, email verification links, OAuth redirect URIs, canonical tags, cache keys. Behind a proxy they often take the host from X-Forwarded-Host instead of Host. PortSwigger's Host header research lists siblings that do the same job in some stacks — X-Host, X-Forwarded-Server, X-HTTP-Host-Override and Forwarded — and notes that sites sometimes support them unintentionally because a third-party component enables them by default.

The best-known payoff is password reset poisoning: the attacker requests a reset for the victim with a host they control, and the emailed link carries a valid token to the attacker's server. We walked through where that sits in a reset flow in how to test a password reset flow for account takeover. From the edge's point of view the fix is simple: set X-Forwarded-Host to the host you actually served, and delete the variants nobody in your stack is meant to send.

3. Path overrides: X-Original-URL and X-Rewrite-URL

Symfony's advisory calls these obsolete IIS headers: they carried the original, pre-rewrite path from a URL rewriter to the application. Frameworks that honored them let the path the app routes on differ from the path the proxy filtered on, which is exactly the lab at the top of this article. Symfony's advisory for CVE-2018-14773 (1 August 2018) describes it as letting “a user to access one URL but have Symfony return a different one which can bypass restrictions on higher level caches and web servers.” HttpFoundation 2.7.0–2.7.48, 2.8.0–2.8.43, 3.3.0–3.3.17, 3.4.0–3.4.13, 4.0.0–4.0.13 and 4.1.0–4.1.2 were affected; 2.7.49, 2.8.44, 3.3.18, 3.4.14, 4.0.14 and 4.1.3 dropped support for both headers.

Symfony removed the feature, but the pattern outlives it: any framework, plugin or legacy IIS-hosted app that reads a “real path” header turns path-based edge rules into suggestions. If no component in your stack needs these headers, there is no reason to forward them.

4. Method overrides: X-HTTP-Method-Override

HTML forms can only send GET and POST, so frameworks offer a way to tunnel PUT, PATCH and DELETE through POST. Express's method-override middleware reads X-HTTP-Method-Override by default and only from POST requests; its documentation warns that allowing other original methods “may introduce security issues and cause weird behavior when requests travel through caches.” Symfony tightened the same feature in 7.4, deprecating overrides to GET, HEAD, CONNECT and TRACE and adding an allowed_http_method_override list.

The risk is a disagreement about what the request is. A WAF rule, an API gateway policy or a CSRF middleware that keys on the method sees POST; the router sees DELETE. Method mismatches are a known access-control failure mode on their own (PortSwigger has a method-based access control lab), and an override header adds one more way to produce one. If your app does not use overrides, strip the header. If it does, this is the one family the edge should inspect rather than drop: restrict the override in the app (POST only, a short allowed list), and make sure any edge rule that keys on the method evaluates the overridden one too.

5. Identity headers from authenticating proxies

This family has the worst failure mode. An authenticating proxy logs the user in and passes the result to the app as a header; the app performs no authentication of its own. If a client can set that header and reach the app, it can be anyone.

  • Grafana's auth proxy mode takes the user from a configured header (X-WEBAUTH-USER in its sample configuration). Its source-IP whitelist option exists, in the docs' words, “to prevent users spoofing the X-WEBAUTH-USER header.”
  • oauth2-proxy passes X-Forwarded-User, X-Forwarded-Email, X-Forwarded-Groups and X-Forwarded-Preferred-Username upstream by default (--pass-user-headers), and strips client-sent copies of headers it would set (--skip-auth-strip-headers, default true). Its --reverse-proxy flag makes it accept forwarded headers, and the docs warn that without --trusted-proxy-ip every source IP is trusted.

oauth2-proxy strips spoofed copies by default; Grafana relies on you configuring the whitelist. Even with both done, deployments break the model: an extra ingress that routes straight to the app, a debug port exposed on the node, a Kubernetes service of type LoadBalancer someone added for testing, a sidecar that reaches the app on localhost. Every one of those is a path where X-Forwarded-User: admin arrives untouched.

For identity headers, stripping at the edge is necessary and still insufficient. The app must be unreachable except through the proxy (network policy, a private listener or mTLS between the two), or it must verify something an outsider cannot forge, such as a signed assertion, rather than a bare username.

6. Framework control headers

Frameworks also send headers to themselves. Next.js used x-middleware-subrequest to stop middleware recursing; because the router did not strip it from external requests, a client could send it and skip middleware entirely. That was CVE-2025-29927, and our teardown of the Next.js middleware bypass covers the payloads and the patch, which authenticated the header instead of trusting it.

You will not find these in a generic list; you find them by reading what your framework, your platform SDK and your own middleware look up on request.headers. Search the dependency tree for header reads with names that sound internal (subrequest, internal, bypass, debug, preview, original) and ask of each one: who is supposed to set this, and what stops a client from setting it first?

How a strip list fails after you write it

Writing the list is the easy part. These are the gaps that remain.

Client sends X-Forwarded-User: admin
A second route in
Origin IP, internal LB, debug port or a service that skips the edge
A config level that drops it
One location block with its own proxy_set_header loses the inherited strip list
A different spelling
Underscore variants map to the same CGI variable as the dashed name
Each path lets client-written headers reach a component that assumes the edge removed them.

The second route

Already covered above, and the most common. Check what answers on the origin's public IP, on every load balancer listener and from inside the cluster. If the app is reachable anywhere the edge is not, the strip list does not protect that path.

nginx's all-or-nothing inheritance

The proxy module documentation states that proxy_set_header directives “are inherited from the previous configuration level if and only if there are no proxy_set_header directives defined on the current level.” A server-level strip list is silently discarded by any location that sets even one header of its own, such as a WebSocket upgrade block. Keep the list in one file and include it in every block that proxies.

Spelling variants

Header names are case-insensitive, so case is not the issue; underscores are. In CGI-style environments (PHP-FPM via FastCGI, for example) header names become variables by upper-casing and turning dashes into underscores, so X-Forwarded-User and X_Forwarded_User land on the same HTTP_X_FORWARDED_USER. A strip rule for the dashed name does not touch the underscored one. nginx defaults to underscores_in_headers off with ignore_invalid_headers on, which drops underscored names, and Apache httpd 2.4 silently drops headers with invalid characters when building CGI variables instead of translating them as earlier versions did. Leave those defaults alone, and check any other proxy or CDN in the chain for the equivalent behavior.

An edge snippet for nginx

This assumes nginx is the first hop that faces the internet. Behind a CDN, use the realip module with set_real_ip_from limited to the CDN's published ranges first, so $remote_addr is the client and not the CDN. Remove any line for a header your stack legitimately sets further in.

# /etc/nginx/snippets/edge-headers.conf
# include this in EVERY server/location that uses proxy_pass:
# proxy_set_header is inherited only when a level defines none of its own.

# Overwrite: these are now facts written by this hop
proxy_set_header Host               $host;
proxy_set_header X-Forwarded-For    $remote_addr;
proxy_set_header X-Real-IP          $remote_addr;
proxy_set_header X-Forwarded-Host   $host;
proxy_set_header X-Forwarded-Proto  $scheme;

# Strip: an empty value means nginx does not pass the header upstream
proxy_set_header Forwarded                      "";
proxy_set_header True-Client-IP                 "";
proxy_set_header X-Host                         "";
proxy_set_header X-Forwarded-Server             "";
proxy_set_header X-HTTP-Host-Override           "";
proxy_set_header X-Original-URL                 "";
proxy_set_header X-Rewrite-URL                  "";
proxy_set_header X-HTTP-Method-Override         "";
proxy_set_header X-Forwarded-User               "";
proxy_set_header X-Forwarded-Email              "";
proxy_set_header X-Forwarded-Groups             "";
proxy_set_header X-Forwarded-Preferred-Username "";
proxy_set_header X-WEBAUTH-USER                 "";
proxy_set_header x-middleware-subrequest        "";

The empty-string behavior is documented: “If the value of a header field is an empty string then this field will not be passed to a proxied server.” A deny-list is still a deny-list, though; it only covers names you thought of. Where your proxy supports it, an allow-list of request headers the app actually uses is stronger, and section 6 is the reason: the dangerous header may be one nobody has written down yet.

Testing a deployment for header trust

From the outside, the method is differential. Send the same request with and without a candidate header and look for any change: status code, redirect target, response length, rate-limit counters, links in emails. A few concrete probes:

  • Path override: request / with X-Original-URL: /does-not-exist. A 404 where you expected the home page means something behind the edge is routing on the header, as in the PortSwigger lab.
  • Host override: trigger an email or redirect with X-Forwarded-Host set to a domain you control, and watch the link or Location header.
  • Client IP: exhaust a rate limit, then add a fresh X-Forwarded-For value per request and see whether the counter resets.
  • Identity: on an app fronted by an auth proxy, look for any route to the app that skips the proxy before trying identity headers at all; through a correctly configured proxy they should already be stripped.

Header guessing is easy to automate, and scanners (Xalgorix included) can send these probes at scale. What automation cannot settle on its own is impact: a changed response length shows the header is read, not that it grants anything. The finding is real when the changed behavior crosses a boundary — a blocked path served, another user's session, a reset link pointing off-site — and that needs a test against the app's actual authorization model, with permission, on a target you are allowed to test.

Give the list an owner

Every family here started as a reasonable convenience, and every one became a bypass when two components disagreed about who wrote the header. The durable fix is organisational as much as technical: one file at the edge, one owner, a review whenever a framework, auth proxy or ingress is added, and a regression test that sends each header from outside and expects it to have no effect.

Ready to see it prove a bug?

Start scanning on Cloud →