
Host Header Poisoning
How applications that trust the HTTP Host header end up with poisoned password reset links, poisoned caches, SSRF and access control bypasses.
Description
Host header poisoning happens when an application reads the HTTP Host header and uses it without checking it. The header names the site the client wants, which is how one server hosts many virtual hosts. The client controls it like any other header.
Developers tend to treat Host as trustworthy and use it to build absolute URLs, check origins and fill in links in outgoing email. Change the header and those URLs point wherever you want. That gives you poisoned reset links, poisoned cache entries, or a way past checks that compare the hostname to a trusted value.
Why it is worth testing
This gets missed often. Password reset poisoning alone can mean takeover of any account whose owner clicks the reset link.
Impact
- Password reset emails carry a link to the attacker's domain, so the reset token leaks when the victim clicks it.
- A cache stores a response built with the attacker's host and serves it to other users.
- Routing based on
Hostsends requests to internal systems or to an attacker-controlled server (SSRF). - Access controls that trust certain hostnames, such as admin panels limited to
localhost, can be reached. - Outgoing email notifications contain attacker-supplied links or content.
Common examples
- Password reset emails linking to
evil.cominstead of the real domain - Cached pages with attacker-controlled script or link URLs served to everyone
- Internal API calls routed through a manipulated
Hostheader - Admin or internal pages opened by sending
Host: localhost - Notification emails with injected links used for phishing
- SSRF against internal services through a reverse proxy that routes on
Host
Detection
- Change
Hostto arbitrary values in Burp Repeater and see what the response does with it. - Burp Scanner and OWASP ZAP both flag some cases of unvalidated
Hosthandling. - Request a password reset for an account you control with a modified
Host(andX-Forwarded-Host), then read the link in the email. - Check whether a cache keeps the response when only the host value changed.
Values worth trying in Host:
evil.comlocalhostinternal.corp.local- Malformed values such as
host:port@evil.com
Remediation
In rough priority order:
- Validate the
Hostheader:- Keep an allowlist of hostnames and compare the incoming header against it.
- Reject requests with a missing or unexpected value.
- Parse the value strictly rather than with substring checks.
- Stop building URLs from the request:
- Take the base URL for password resets and other sensitive links from configuration.
- Never derive it from
HostorX-Forwarded-Host.
- Configure the web server:
- Add a default virtual host that rejects unknown hostnames.
- Return an error or a static page for anything that does not match.
- Redirect to the canonical hostname at the server level.
- Behind reverse proxies and load balancers:
- Validate
X-Forwarded-Host, or strip it at the edge if the application does not need it. - A Content Security Policy limits where injected resource URLs can load from.
- A strict
Referrer-Policykeeps reset tokens in URLs from leaking through theRefererheader.
- Validate
- Framework settings:
- Django: set
ALLOWED_HOSTSto the real hostnames. - Express.js/Node.js: add middleware that checks the host against an allowlist.
- ASP.NET: do not trust
HttpContext.Request.Url.Hostfor URL generation.
- Django: set
Example configurations
-
Nginx
server { listen 80 default_server; server_name _; return 444; # Drop connection for invalid hosts } server { listen 80; server_name example.com www.example.com; # Application configuration } -
Apache: the first
VirtualHostfor an address is the default, so in a real config put the catch-all block first.<VirtualHost *:80> ServerName example.com ServerAlias www.example.com # Application configuration </VirtualHost> <VirtualHost *:80> ServerName _default_ DocumentRoot /var/www/html/error # Catch-all for invalid hosts </VirtualHost> -
Application-level validation
# Python/Django example ALLOWED_HOSTS = ['example.com', 'www.example.com'] def validate_host(request): host = request.get_host() if host not in settings.ALLOWED_HOSTS: raise DisallowedHost("Invalid host header")
Verification
After the fix:
- Send malicious
Hostvalues and confirm they are rejected. - Trigger a password reset and confirm the link uses the configured domain.
- Confirm the cache does not store responses built from a modified host.
- Confirm internal routes cannot be reached by changing the header.
References
- PortSwigger Web Security Academy: Host Header Attacks
- OWASP: Host Header Injection
- CWE-20: Improper Input Validation
Next steps
If you find host header poisoning, list every place the application uses the header to build a URL, since the reset link is rarely the only one. Related notes:
Directory Listing
How directory listing (indexing) can leak sensitive files and metadata, why it matters, and practical mitigations for web servers and cloud storage.
Insecure Deserialization: Object Manipulation Attacks
Exploiting deserialization of untrusted data in Java, PHP, Python, .NET and Node.js, from spotting serialized blobs to gadget chains and fixes.