Skip to content
Account takeover Write-up Intermediate

Host Header Injection — How I Manipulated Session Cookie Domain

The server set the session cookie's Domain attribute directly from the client-supplied Host header without validation. An attacker could make the cookie scoped to an arbitrary domain, potentially leading to session hijacking if the victim later visits that domain.

Krithick Follow

Published on medium.com

Some vulnerabilities are elegant in how simple they are. No complex exploit chain.

Krithick, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application trusted the client-supplied Host header to set the cookie's Domain attribute without validation, and handled multiple Host headers inconsistently.

Impact

An attacker could set a victim's session cookie to be scoped to an attacker-controlled domain, potentially leading to session hijacking if the victim later visits that domain; the parent-domain variant could expose cookies across all subdomains if any subdomain has an XSS vulnerability.

What the attacker needed

Victim visits a crafted link or request; victim later visits attacker.com or is redirected

The fix

The cookie domain should be hardcoded in server configuration, requests with multiple Host headers should be rejected, and any use of the Host header should be validated against a whitelist.

How it was found

  1. Send a normal request to the API and observe the cookie Domain matches the real server domain.
  2. Send a request with a custom Host header set to attacker.com and observe the cookie Domain becomes attacker.com.
  3. Send a request with a Host header set to the parent domain (with a leading dot) and observe the cookie Domain becomes that parent domain.
  4. Send a request with two Host headers (attacker.com first, the real domain second) and observe the cookie Domain is still attacker.com while the request is routed normally.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When you log in, a website gives your browser a small file called a cookie so it remembers you. The cookie has a rule about which websites it can be sent to, called its Domain. This server let the visitor's request decide that rule, so an attacker could make the cookie belong to their own website and steal the login session.

What is Account takeover?

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.

More by Krithick

View all

4 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.