CDN Cache Security and Cache Poisoning
What you'll learn: How attackers manipulate CDN caches to serve malicious content and how to prevent it.
What Is Cache Poisoning?
A CDN caches content at edge locations to speed up delivery. The CDN decides what to cache based on a cache key—typically the URL path. But here's the problem: if the CDN ignores certain HTTP headers when creating the cache key but the origin server uses those headers to generate responses, an attacker can poison the cache.
Analogy: Imagine a library that files books only by title. An attacker slips a fake page into "Security 101" when requesting it with a special bookmark. Now everyone who asks for "Security 101" gets the poisoned version, because the library doesn't track the bookmark—only the title.
How Cache Poisoning Works
- Attacker sends a crafted request with a manipulated header (e.g.,
X-Forwarded-Host: evil.com) - CDN ignores the header for cache key purposes but forwards it to the origin
- Origin reflects the header in the response (e.g., in a JavaScript redirect)
- CDN caches the poisoned response under the normal URL
- All subsequent users receive the malicious content
Key Vulnerabilities
- Header manipulation: Exploiting headers like
X-Original-URL,X-Forwarded-Host,X-Custom-IP-Authorization - Cache deception: Tricking the CDN into caching sensitive content (e.g.,
/account.php/static.csscaches as static but serves dynamic data) - Unkeyed parameters: Query strings or headers the CDN doesn't include in the cache key
Prevention Strategies
- Include security-relevant headers in cache keys
- Validate and sanitize all input at the origin, especially reflected headers
- Set strict
Cache-Controlheaders for dynamic content - Disable caching for personalized or sensitive pages
- Monitor for anomalous cache behavior
Key Takeaway: Cache poisoning exploits mismatches between what the CDN uses to cache content and what the origin uses to generate it—secure both the cache key composition and origin input handling.