HTTP headers in security testing: which ones the server trusts and which ones protect users
Request headers that applications wrongly trust (Host, X-Forwarded-For, X-Original-URL, Referer), response headers that protect users (CSP, HSTS, frame-ancestors), and how to audit both with curl and a proxy.
Diagram
Headers the server should and should not trust
Step 1 of 4
Client-set
Host, X-Forwarded-For, Referer, User-Agent are all chosen by the client.
curl -s -o /dev/null -w "%{http_code}\n" -H "X-Forwarded-For: 10.0.0.5" https://app.example.test/adminThe example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
IP allow-lists by header
- What fails
- Admin areas that trust X-Forwarded-For can be reached by setting it.
- Who is affected
- Everything behind the admin area.
- What you would notice
- Access decisions logged with a client-supplied forwarded address.
- What you change
- Have the edge proxy overwrite the header and trust only the proxy’s value.
Override headers
- What fails
- Some frameworks honor X-Original-URL or X-HTTP-Method-Override, which can bypass path or method rules at the proxy.
- Who is affected
- Routes protected only at the proxy layer.
- What you would notice
- A blocked path served when the header names it.
- What you change
- Disable override headers or strip them at the edge.
Missing protective headers
- What fails
- Without HSTS, CSP, and frame-ancestors, browsers fall back to permissive behavior.
- Who is affected
- Users on hostile networks or on framed pages.
- What you would notice
- A scan showing no Strict-Transport-Security or Content-Security-Policy.
- What you change
- Set the baseline headers at the edge and test with a header scanner.
Auditing response headers
Fetch the main pages and the API with curl -I and compare against the baseline. Check that HSTS appears on every HTTPS response, that CSP does not contain unsafe-inline for scripts, and that error pages carry the same headers as normal ones.
$ curl -sI https://app.example.test | grep -iE "strict-transport|content-security|x-content-type|referrer-policy" strict-transport-security: max-age=31536000; includeSubDomains x-content-type-options: nosniff # missing: content-security-policy, referrer-policy -> finding
Testing request header trust
In your proxy, replay a request to a restricted path with X-Forwarded-For set to an internal address, with Host changed, and with override headers added. Each should behave exactly like the original. Differences are findings; the host header injection and hop-by-hop pages go deeper on two of them.
Headers that leak
Server, X-Powered-By, and verbose error headers reveal versions. Removing them is minor hardening; patching is what matters.
Check yourself
Recognition and the fix. Nothing here is a procedure.
An admin page allows access when X-Forwarded-For is 10.0.0.5. What is wrong?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.