Course contentsShow
← Security
Lesson 1865 of 3,05237. Cloud Security - Network ArchitectureFree lesson

CDN Cache Security and Cache Poisoning

Understanding cache key composition, preventing cache poisoning attacks, header manipulation, and cache deception vulnerabilities.

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

  1. Attacker sends a crafted request with a manipulated header (e.g., X-Forwarded-Host: evil.com)
  2. CDN ignores the header for cache key purposes but forwards it to the origin
  3. Origin reflects the header in the response (e.g., in a JavaScript redirect)
  4. CDN caches the poisoned response under the normal URL
  5. 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.css caches 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-Control headers 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.