CIDADAXSEC
← All topics
Expert

HTTP Host header attacks

Host header attacks forge the Host header to bypass validation, redirect routing, poison password resets, or achieve SSRF.

Material

The Host header tells a web server which hostname the client asked for. Reverse proxies, load balancers, and origin servers often parse requests differently, and some applications trust the value without validation. A forged header can therefore redirect a request, void host-based access checks, or contaminate links sent to users.

How Host-based routing works

In a layered setup the request first hits a proxy that decides the route from Host, then forwards to the origin. If the proxy uses Host while the origin builds links or redirects from a different value, the two can reach different conclusions about the same request. That gap is what gets exploited: the attacker sends a different Host so proxy and origin interpret the request differently.

http
POST /reset HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded

email=victim@corp.test
http
POST /reset HTTP/1.1
Host: example.com.evil.test
Content-Type: application/x-www-form-urlencoded

email=victim@corp.test

The password reset case is the most damaging example. The application builds a reset link from the Host value without verifying it, and the victim address appears inside that link. Swapping in a forged Host makes the reset link point at the attacker domain, so the reset token ends up with the wrong party and the victim account is taken over.

Attack forms

  • Authentication bypass: a host configured for an internal environment is checked only via the Host header, so it can be forged.
  • Password reset poisoning: the reset link is built from a forged Host and redirected to the attacker domain.
  • Routing-based SSRF: the Host value steers the proxy to an internal service that is not exposed publicly.
  • Flawed parsing: proxy and origin read Host or similar headers differently, creating a trust gap.
  • Connection state: a machine that established the connection first receives the next request as its own, ignoring the Host guard.
  • Dangling markup: an unclosed HTML payload makes the victim browser send the remaining token to the attacker domain.

Prevention

  • Use a host allowlist and always validate the Host header against the list of legitimate domains before processing a request.
  • Build absolute URLs from configuration allowlists rather than from a per-request header value.
  • Add a random nonce to password reset links so tokens cannot be guessed or broken outside the server.
  • Make proxy and origin parse Host consistently, and strip hop-by-hop headers that are not needed.
  • Disable Host-based redirection in other layers such as the load balancer and framework.
  • Test the application with an unknown Host to confirm no behavioural differences leak.
http
# Server harus menolak Host di luar allowlist
const ALLOWED = new Set(['app.example.com', 'api.example.com']);
const host = (req.headers.host || '').split(':')[0].toLowerCase();
if (!ALLOWED.has(host)) {
  res.writeHead(400).end('Invalid Host');
} else {
  route(req, res);
}
The principle is simple: Host is client input and must be treated like any other parameter, meaning validated rather than trusted. Relying on extra marker headers such as X-Forwarded-Host rarely helps, because the client controls those too.

Labs in this topic

Labs run on a domain separate from this site, so a payload cannot reach your account session.

Labs for this category land in Phase 2. The material is readable now.

Challenges in this category

Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.