Host Header Injection Explained: The Bug That Poisons Password Resets
Every HTTP request carries a Host header. It tells the server which website the browser thinks it is talking to, and it matters most when one server hosts many sites. Most of the time it is boring plumbing. But when a web application builds links — especially password-reset links — from the Host header without checking it, a single header becomes a full account-takeover bug. Bug bounty hunters love it because it is easy to test and often pays well.
How the Attack Works
Picture a normal password reset. You click "forgot password", the app generates a secret token, and it emails you a link like:
https://example.com/reset?token=abc123
The problem is where example.com comes from. Many frameworks build that link from the incoming request's Host header. An attacker can send the reset request for the victim's account with a fake Host header:
POST /forgot-password HTTP/1.1
Host: evil.com
...
email=victim@example.com
If the app trusts the header, the email now contains https://evil.com/reset?token=abc123. The victim clicks the link they trust, lands on the attacker's server, and the token leaks in the request. The attacker uses the token to reset the victim's password and takes over the account. The victim did nothing wrong — they just clicked a link from a legitimate email.
How to Test It (Legally)
Only test applications you own or have written permission to test — a bug bounty program's scope, or your own lab app. The test is simple:
- Send a password-reset request with a modified Host header pointing at a domain you control, like
Host: attacker.example. - Check the reset email. If the link uses your domain, the app is vulnerable.
- Try variations: some apps ignore the Host header but trust
X-Forwarded-Hostinstead, which is the same bug through a different header.
Report it with the full request, the email you received, and the impact — account takeover with one click from the victim.
How to Fix It
The fix is straightforward, and it belongs in every web app:
- Never build absolute URLs from the Host header. Store your real domain in configuration and use that for emails and links.
- Validate the Host header against an allowlist if you must use it. Reject anything that is not your domain.
- Use a framework's built-in URL generation, which usually defaults to a configured host rather than the request header.
- Watch your reverse proxy too. A proxy that forwards the original Host header is fine — the app behind it must still not trust it blindly.
Host header injection is a small bug with an outsized impact. One unchecked header, one trusted email, one clicked link — and an account is gone. That is why it keeps showing up in bounty reports, and why fixing it is a ten-minute job every developer should do.


Comments
Post a Comment