Host header injection: when the server builds links from a header the client chose

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

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

Diagram

A reset link built from Host

Follow the path. One example at a time.

Step 1 of 4

Request

A reset request arrives with a changed Host header.

Illustration: Request
POST /password/reset HTTP/1.1
Host: attacker.example.net

email=ana@example.org

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. Reset poisoning

    What fails
    A reset link pointing at another domain leaks the token when the user clicks it.
    Who is affected
    Any user whose email address is known.
    What you would notice
    Reset emails containing the request Host.
    What you change
    Use a configured base URL for all emailed links.
  2. Cache poisoning

    What fails
    Caches that key on path but not Host can store a response built for a changed Host.
    Who is affected
    Every visitor served the poisoned cache entry.
    What you would notice
    Absolute URLs in cached pages that reflect Host.
    What you change
    Include Host in cache keys and reject unknown hosts at the edge.
  3. Routing confusion

    What fails
    Virtual hosting may route an unknown Host to a default site, sometimes an internal one.
    Who is affected
    Owners of the default virtual host.
    What you would notice
    An internal admin site served as the default.
    What you change
    Make the default server return an error.

Testing

With your own test account, request a password reset while the proxy changes Host or adds X-Forwarded-Host, then read the email. The link should always use the real domain. Also request a page with an unknown Host and check that the edge refuses it.

$ curl -s -o /dev/null -w "%{http_code}\n" -H "Host: unknown.example.net" https://203.0.113.10/
444 / 400 / 421 expected; 200 with the app means unknown hosts are served

Notes

Frameworks expose helpers such as request.build_absolute_uri or url_for with _external that read Host. Audit their use in emails and redirects.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

A reset email contains a link to the domain in the request’s Host header. What can happen?

Go deeper

Specific techniques, exercises, and glossary cards for this topic.

  1. 01HTTP headers in security testing: which ones the server trusts and which ones protect usersRequest 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. Includes the diagram and a defensive fix.
  2. 02Hop-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. Includes the diagram and a defensive fix.