Host Header Injection
The application trusts the client-supplied Host header, or a forwarding header that overrides it, when it builds links, redirects or routing decisions.
| Severity | Medium |
| CVSS 3.1 | 5.4 CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N Open in the calculator |
| CVSS 4.0 | 5.1 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-348: Use of Less Trusted Source |
| MITRE ATT&CK | T1190 Exploit Public-Facing Application |
| Category | Input Validation |
Description
The application, or the web server or proxy in front of it, treats the Host request header as a trusted statement of its own name, although the client sets it. Override headers such as X-Forwarded-Host, X-Host and Forwarded are often trusted in the same way when the application sits behind a proxy. The value is then used to build absolute URLs in pages, redirects and emails, such as password reset links, to choose a site or tenant, or to decide whether a request is internal.
The most common consequence is password reset poisoning: an attacker requests a reset for a victim with a host value pointing to their own server, and receives the token when the victim, or a mail security product that opens links, follows the link in the genuine email. The same weakness can let an attacker poison shared caches with links to their server and reach internal virtual hosts or administration interfaces. Where a reverse proxy routes requests by host name, setting the header to an internal address can reach internal systems, using the proxy for server-side request forgery.
The weakness typically shows itself on a test when a modified Host header, or an added override header, is reflected in links, redirect locations or generated emails, or when changing it reaches a different virtual host. Ambiguous requests, such as duplicate Host headers or an absolute URL in the request line, can bypass validation that checks only one of the values. Scanners commonly flag the issue when an injected host value appears in a response, but reflection alone, without a cache or an email, is of limited use, because a victim's browser always sends the correct host.
Remediation
Stop using the request as the source of the application's own name:
- Configure the canonical host name, or names, in the application and build absolute URLs, especially those in emails, from that configuration rather than from the request.
- Validate the
Hostheader against an allowlist of expected names and reject other values. Most frameworks provide a setting for this, such asALLOWED_HOSTSin Django andAllowedHostsin ASP.NET Core. - Give the web server or load balancer a default virtual host that rejects requests for unknown names, so that only expected names reach the application.
- Trust
X-Forwarded-HostandForwardedonly when they are set by the organisation's own proxy, which should overwrite any value sent by the client, and ignore them otherwise. - Make reverse proxies route only to an explicit list of back ends rather than to the host named in the request.
Confirm the fix by repeating the original requests with modified, duplicated and override host headers, and checking that they are rejected or ignored.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.