Back to Blog
Application Security

Web Cache Poisoning: Weaponizing CDNs Against Your Users

5 min read
Cache PoisoningCDN SecurityWeb Attacks

What is Web Cache Poisoning?

Web Cache Poisoning is an attack where a malicious actor manipulates a web cache to serve harmful content to other users. By sending specially crafted requests that include attacker-controlled content in "unkeyed" headers, the cache stores and serves the poisoned response to subsequent visitors.

This attack is particularly dangerous because it amplifies impact: a single malicious request can affect thousands of users who receive the cached response.

How Cache Poisoning Works

Cache Key Fundamentals

Caches store responses indexed by a "cache key," typically composed of:

  • Keyed components: Request method, URL path, query parameters, Host header
  • Unkeyed components: Other HTTP headers (X-Forwarded-Host, X-Original-URL, etc.)

The vulnerability arises when the application uses unkeyed inputs to generate the response, but the cache doesn't include them in the key.

Attack Flow

  1. Attacker sends: GET / HTTP/1.1 Host: example.com X-Forwarded-Host: evil.com
  2. Application generates response using evil.com in asset URLs
  3. Cache stores response keyed only by GET / example.com
  4. Legitimate users requesting GET / example.com receive the poisoned response
  5. Their browsers load scripts from evil.com

Attack Variants

Header-Based Poisoning

Exploiting headers that influence response content:

X-Forwarded-Host: attacker.com
X-Forwarded-Scheme: http  (forces HTTP redirect to attacker)
X-Original-URL: /admin    (accesses restricted paths)

Fat GET Requests

Some frameworks process request bodies on GET requests:

GET /api/data HTTP/1.1
Content-Type: application/json

{"callback": "<script>alert(1)</script>"}

Cache Key Normalization Exploits

Differences in how caches and applications normalize URLs:

/page?param=1  (cache key)
/page?param=1&evil=<script>  (different URL, same cache key after normalization)

Web Cache Deception

The inverse is tricking the cache into storing a user's private page:

GET /account/settings/nonexistent.css HTTP/1.1
Some caches see .css and cache the response, which contains the user's account page.

Detection Techniques

1. Identify Unkeyed Inputs

Send requests with unique values in each header and observe if they appear in the response:

headers_to_test = [
    "X-Forwarded-Host", "X-Forwarded-Scheme",
    "X-Original-URL", "X-Rewrite-URL",
    "X-Forwarded-For", "X-Custom-IP-Authorization"
]

2. Confirm Cacheability

Check response headers for caching indicators:

  • Cache-Control: public, max-age=3600
  • X-Cache: HIT vs X-Cache: MISS
  • Age: 120 (response served from cache)

3. Verify Poisoning

  1. Send a poisoned request with a unique marker
  2. Send a normal request from a different session
  3. Check if the normal request receives the poisoned response

Prevention

1. Strict Cache Key Configuration

Include all headers that influence response content in the cache key, or strip them before caching.

2. Disable Unnecessary Headers

Don't process X-Forwarded-Host, X-Original-URL, or similar headers unless required. If needed, validate them strictly.

3. Cache-Control Headers

Use Cache-Control: private for personalized content. Use Vary headers correctly:
Vary: X-Forwarded-Host, Accept-Encoding

4. CDN Configuration

Audit CDN rules to ensure sensitive pages aren't cached and that file extension-based caching rules don't apply to dynamic routes.

Testing with SuperClue

SuperClue's active scan tests Host header and forwarding header injection, such as X-Forwarded-Scheme, which are common routes to cache poisoning. It does not audit your CDN configuration.

Protect your CDN from serving malicious content to your users.

Ready to Test Your Applications?

Start your comprehensive security scan with SuperClue's security modules.

Request access