Skip to main content
HighHost validationOWASP A03:2021CWE-644

How to fix: Host Header Injection Risk

The response reflects the X-Forwarded-Host header value or appears to use user-supplied host information in links, emails, or redirects. Host header injection allows attackers to poison password reset emails with an attacker-controlled domain.

Why it matters

Password reset links poisoned via Host header injection redirect victims to the attacker's domain, stealing reset tokens. Cache poisoning via host injection can serve malicious content to all users from a shared cache.

Web applications often construct absolute URLs using the Host request header (e.g., for password reset links). If the application trusts X-Forwarded-Host or accepts arbitrary Host headers, an attacker can inject a different domain and have the application send links pointing there.

How to fix it

  1. 1Hardcode the application's canonical hostname in configuration, never derive it from the Host header.
  2. 2Use ALLOWED_HOSTS validation: reject requests with Host headers not in the allowlist.
  3. 3In Django: configure ALLOWED_HOSTS. In Rails: configure config.hosts. In Express: validate req.hostname against a whitelist.
  4. 4For password reset emails: always use the configured APPLICATION_URL, never request.host.

Code examples

Safe absolute URL generation

TypeScript
// Bad: Host header poisonable
const resetUrl = `${req.protocol}://${req.get('host')}/reset?token=${token}`;

// Good: use configured base URL
const resetUrl = `${process.env.APP_URL}/reset?token=${token}`;

References

Detected automatically by VulnRadar. The check id is host-header-injection, stable across every scan so you can filter or diff on it.

See every host validation check

Questions

How severe is Host Header Injection Risk?
VulnRadar rates this high severity in the host validation category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id host-header-injection, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Host Header Injection Risk map to?
It maps to CWE-644. In the OWASP Top 10 it falls under A03:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for host header injection risk

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Host Header Injection Risk | VulnRadar