Skip to content
Pwnversity
WEB-HOSTHEADERintermediate · 6 min · upd. 2026-10

Host header injection

OWASP A02:2025CWE-644

Many apps use the Host header (or X-Forwarded-Host) to build absolute URLs: email links, resources, redirects, canonicals. If they trust it without validation, the attacker manipulates it to poison password-reset links, the cache, cause SSRF or reach internal vhosts. The Host value is set by the client, so it’s untrusted input: the invariant broken is “the host that builds the link is the host the victim asked for”.

flowchart LR
    A[Attacker] -->|"POST /forgot-password with Host: evil.tld"| S[Reset app]
    S -->|"builds link with the received Host"| M["Email to victim:<br/>https://evil.tld/reset?token=..."]
    M -->|"victim clicks"| E[Attacker server]
    E -->|"captures the reset token"| A2[Attacker → ATO]
  • Password reset poisoning: the reset link points to the attacker’s domain → the victim clicks → the token leaks via Referer/the request to the attacker domain → ATO.
  • Web cache poisoning (if Host/X-Forwarded-Host enters the cached response; see cache).
  • SSRF / routing: reach internal vhosts or panels by name (see SSRF).
  • Information leakage and bypass of host-based controls.

The server generates, say, the reset link with https://<Host>/reset?token=.... If the framework takes the Host (or a proxy header like X-Forwarded-Host) to form that URL, controlling the header is controlling the link’s domain. The token is still the victim’s (the server generates it for her account), but it travels to the attacker’s domain when she clicks the link or when her browser sends the Referer.

  • Change Host: directly.
  • Add X-Forwarded-Host: evil.tld (many frameworks prioritize it over Host).
  • Other proxy headers: X-Host, X-Forwarded-Server, Forwarded.
  • Double Host or Host: victim.tld:@evil.tld / Host: victim.tld\n Host: evil.tld depending on how the server parses.
  • Injected port: Host: victim.tld:badport (sometimes reflected verbatim).
  • Dangling markup via Host when reflected unescaped in the page.

Try changing Host and adding forwarding headers on endpoints that generate links or reflect the host. Password reset is the classic target.

POST /forgot-password HTTP/1.1
Host: evil.tld
Content-Type: application/x-www-form-urlencoded
email=victim@tld.com

If the framework honors Host, the email the victim receives links to https://evil.tld/reset?token=VICTIM_TOKEN. If it validates Host but trusts the proxy, try keeping the real Host and adding the forwarding header:

POST /forgot-password HTTP/1.1
Host: victim.tld
X-Forwarded-Host: evil.tld
Content-Type: application/x-www-form-urlencoded
email=victim@tld.com
GET / HTTP/1.1
Host: evil.tld"><script>alert(document.domain)</script>

If evil.tld (or the markup) appears in the response —in a link, a <base href> or a script—, it can lead to XSS or, if the response is cached with Host as an incorrect key, to cache poisoning.

GET / HTTP/1.1
Host: internal-admin

If the reverse proxy routes by Host, an internal name can expose a panel not meant for the Internet.

  1. Locate endpoints that generate links (reset, invitations, email verification).
  2. Inject controlled Host/X-Forwarded-Host and retrieve the test email.
  3. Check whether the link uses your domain → poisoning PoC.
  4. In parallel, test host reflection (cache/XSS) and routing to vhosts.

Burp Suite (modify Host/X-Forwarded-Host in Repeater), Param Miner to discover unkeyed headers the back-end still honors.

Password reset poisoning is direct ATO. Host reflection chains with cache poisoning and XSS; host routing, with access to internal panels.

Requests with Host/X-Forwarded-Host that don’t match expected domains; reset links to external domains; duplicate Host headers; reset spikes with anomalous hosts.

Reverse-proxy/WAF logs with Host and X-Forwarded-* headers, app logs with the generated URL, and the edge cache-key configuration.

  1. Don’t build URLs with the request Host. Use a configured canonical domain.
  2. Allow-list valid hosts; reject (400) requests with an unexpected Host (in Django, ALLOWED_HOSTS).
  3. Ignore X-Forwarded-Host unless it comes from a controlled trusted proxy.
  4. For reset, generate the link with the canonical domain, never the received Host.

Invalidate potentially leaked reset tokens, fix link generation, and review poisoned caches.

  • Password reset poisoning via host header has affected multiple frameworks and apps (popular CMS and custom applications); a bug-bounty classic with ATO impact from reset-token theft. The reference research is “Practical HTTP Host header attacks” by James Kettle (PortSwigger).
  • Several platforms have suffered cache poisoning through X-Forwarded-Host; it’s why frameworks like Django introduced ALLOWED_HOSTS.

Product-specific CVEs/incidents in NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).

  • Changing Host and adding X-Forwarded-Host/X-Host on reset tested.
  • Confirmed whether the email link uses the injected host.
  • Host reflection in the response tested (cache/XSS).
  • Variants tested (double Host, @, port) depending on the parser.
  • Internal vhost access / routing evaluated.