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

Cache Poisoning via HTTP Header Injection

Exploiting X-Forwarded-Host, X-Original-URL, and other headers to inject malicious content into cached responses.

Cache Poisoning via HTTP Header Injection

You'll learn how attackers exploit headers like X-Forwarded-Host to inject malicious content that gets cached and served to all users.

What Is This Attack?

Web caches use certain HTTP headers to decide what to store and serve. However, many caches treat some headers as unkeyed inputs—they don't include them in the cache key but still use them when generating responses. Attackers can manipulate headers like X-Forwarded-Host, X-Original-URL, or X-Forwarded-Scheme to poison the cached response with malicious content that affects every subsequent visitor.

How It Works

Think of a cache like a photocopier. The copier decides which document to retrieve based on the page number (the cache key), but ignores margin notes. If the server uses those margin notes to add content to the page before copying, an attacker can write malicious margin notes that get permanently copied into the cached version everyone receives.

Common vulnerable headers:

  • X-Forwarded-Host - May influence generated URLs or redirects
  • X-Original-URL - Can alter which resource gets cached under a key
  • X-Forwarded-Scheme - Affects protocol in generated links

For example, an attacker might send:

GET /home HTTP/1.1
Host: victim.com
X-Forwarded-Host: evil.com

If the server uses X-Forwarded-Host to build JavaScript URLs like <script src="https://evil.com/app.js"> and the cache stores this poisoned response, all users requesting /home receive the attacker's script.

Why It's Dangerous

This transforms a single malicious request into a persistent XSS or malware distribution affecting everyone who hits the cached page—potentially thousands of users—until the cache expires.

Key Takeaway: Cache poisoning via header injection exploits unkeyed headers that influence response content, allowing attackers to store malicious data in the cache and weaponize it against all subsequent users.