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.

Lesson 11 of 69 · 13 min read · practice only with authorization

Diagram

Headers the server should and should not trust

Follow the path. One example at a time.

Step 1 of 4

Client-set

Host, X-Forwarded-For, Referer, User-Agent are all chosen by the client.

Illustration: Client-set
curl -s -o /dev/null -w "%{http_code}\n" -H "X-Forwarded-For: 10.0.0.5" https://app.example.test/admin

The 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.

  1. 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.
  2. 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.
  3. 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.

1 / 3

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.

  1. MapHost header injection: when the server builds links from a header the client choseHow applications use the Host header to build password-reset links, redirects, and cache keys, how a changed Host poisons those, and how to pin the public hostname in configuration.
  1. 01Hop-by-hop headers: when a client can make a proxy drop the headers that carry trustHow the Connection header lets a client ask a proxy to strip named headers, why that matters when a backend trusts a header the proxy adds, and how to test and configure proxies so it cannot remove security headers.

Practice

  1. LabControl benchA failure is described. Choose the control that changes the outcome.