Course contentsShow
← Security
Lesson 1127 of 3,05223. Web Security - Modern Web AttacksFree lesson

Web Cache Poisoning via Host Header

Leveraging Host header manipulation to poison caches and serve malicious content to legitimate users.

Web Cache Poisoning via Host Header

What You'll Learn

You'll learn how attackers manipulate the Host header to trick caches into storing and serving malicious content to legitimate users.

The Attack Surface

You already know that the Host header identifies which website you're trying to reach and that attackers can inject malicious values. You've also learned about web caches and how they can be poisoned with unkeyed inputs. Now we combine both vulnerabilities into a powerful attack.

How the Attack Works

Web caches often ignore the Host header when determining what to cache (it's "unkeyed"), but the application itself uses it to generate content—especially links, redirects, and resource URLs. Here's the attack chain:

Step 1: The attacker sends a request with a poisoned Host header:

GET /resources/js/tracking.js HTTP/1.1
Host: evil.com

Step 2: The vulnerable application uses this Host header to build URLs in the response:

<script src="http://evil.com/resources/js/tracking.js"></script>

Step 3: The cache stores this poisoned response under the URL path (ignoring the Host header as a cache key).

Step 4: Legitimate users request the same resource with the correct host, but the cache serves them the poisoned response containing links to evil.com.

The Real Danger

This is particularly devastating because:

  • Scale: One poisoned request affects all users until cache expiration
  • Trust: Users receive malicious content from domains they trust
  • Persistence: The poisoned cache entry can last minutes to hours
  • Stealth: The attack happens at the cache layer, not the application

Key Takeaway: Web cache poisoning via Host header combines header injection with cache mechanics to serve attacker-controlled content to legitimate users at scale, making proper Host header validation and cache key configuration critical defenses.