Cache Poisoning Attack Fundamentals
What you'll learn: How attackers manipulate cached responses to serve malicious content to all users requesting the same resource.
What Is Cache Poisoning?
Cache poisoning is an attack where a malicious actor tricks a web cache (like a CDN or reverse proxy) into storing a harmful response. Once poisoned, the cache serves this malicious content to every user who requests that resource—until the cache expires or is purged.
Think of it like poisoning a town's water tower. Instead of contaminating each person's glass individually, you contaminate the central supply, and everyone who drinks from it gets poisoned automatically.
How the Attack Works
Web caches store responses based on a cache key—typically the URL and Host header. However, many other headers (like X-Forwarded-Host, User-Agent, or custom headers) influence the response but aren't part of the cache key.
Attackers exploit this mismatch:
- Find an unkeyed input: A header or parameter that affects the response but isn't in the cache key
- Craft a malicious request: Use that input to generate a harmful response (e.g., XSS payload, redirect to phishing site)
- Poison the cache: Send the request so the cache stores the malicious response
- Wait for victims: All subsequent users requesting that URL receive the poisoned content
Real-World Impact
A poisoned cache can:
- Inject JavaScript into pages (XSS at scale)
- Redirect users to phishing sites
- Serve defaced content
- Bypass security controls
The attack is particularly dangerous because it affects all users, not just the attacker's session, and persists until cache expiration.
Key Takeaway: Cache poisoning exploits the gap between what influences a cached response and what identifies it in the cache, allowing attackers to serve malicious content to entire user populations through a single poisoned request.