← All tracks
Web InfrastructureWeb Cache Poisoning10 labsAdvanced7h practice

Web Cache Poisoning: Shared Memory Without an Identity

If an input changes the response but not the cache key, the cache can be poisoned.

“The cache remembered a page for everyone. The attacker taught it a secret.”

CWE-444OWASP Top 10 A05:2021OWASP ASVS 14.4.1
The mental model
A cache is shared memory. Its key is a policy about which inputs define a distinct response. Any input that changes the body but is missing from the key can poison every later visitor.

The edge caches by path only, but the origin renders a page using a forwarding header. The attacker sends the internal header first; the poisoned response is stored and served to normal requests.

We test the response. Attackers test the memory that serves it.

Threat model

What is actually at stake?

Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.

Assets

  • Shared HTML and API responses
  • Redirects and error pages
  • User-specific fragments
  • Brand trust and session flows

Actors

  • Unauthenticated attacker who can reach the cache
  • Attacker with one victim interaction
  • Cache administrator with a permissive configuration

Trust boundaries

  • Request header to cache key
  • Origin response to cached object
  • CDN normalization to origin normalization
  • Cache TTL to victim request

Abuse cases

  • Poison X-Forwarded-Host into a cached page
  • Use an unkeyed query parameter or cookie
  • Exploit a fat GET or method override
  • Cache a redirect to an attacker domain
  • Poison a JavaScript or API response used by many users
PrerequisitesHow shared caches and CDNs key responsesRequest headers and URL normalizationCache-Control and Vary semantics
Request anatomy

Follow the decision, not the payload

Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.

  1. 01

    Request

    A client sends a request with headers, cookies, query parameters and a path.

  2. 02

    Key

    The cache derives a key from a subset of the request, often host, path and selected headers.

  3. 03

    Miss and forward

    On a miss, the request goes to the origin, which may use an unkeyed input in the response.

  4. 04

    Store

    The cache stores the response under the key, including the attacker-influenced content.

  5. 05

    Serve

    Later victims with the same key receive the poisoned response until it expires or is purged.

Case study

Practical web cache poisoning research, 2018-2019

Public web cache poisoning research, 2018-2019
Context

Public research demonstrated that many CDNs and reverse proxies keyed responses on a subset of request attributes while origins consumed additional headers and parameters.

Discovery

Researchers found unkeyed inputs such as X-Forwarded-Host that changed the origin response but not the cache key. A single request could then poison a shared page.

Impact

Poisoned pages redirected users, loaded attacker scripts or exposed cached user data. The attack required no authentication and could affect every visitor.

Root cause

The cache and origin disagreed about which parts of the request determined the response. The cache stored a response that was not safe for the key.

Fix

Normalize and validate inputs at the edge, include every response-affecting input in the key or strip it, avoid caching personalized or error responses, and purge on anomalies.

Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.

Attacker lens

A repeatable testing sequence

  1. Identify cacheable routes and response headers such as Age, X-Cache and Cache-Control.
  2. Find headers or query parameters that change the body but are not in the key.
  3. Send the poisoning input, then request the same path normally.
  4. Confirm the poisoned content is served from cache.

Where smart people get fooled

  • HTTPS does not make a shared cache safe.
  • A cache may ignore cookies but still cache the body.
  • A single request may prime the cache without showing the effect.
Detection engineering

What would the logs show?

A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.

  • Responses containing attacker-controlled hosts or scripts under a shared cache key
  • Cache HIT on a response that should be personalized
  • Unkeyed headers such as X-Forwarded-Host, X-Original-URL or X-HTTP-Method-Override
  • A sudden purge or cache miss spike after a suspicious request
  • The same response body served to clients with different cookies
Starter query
index=cdn sourcetype=cache | eval suspicious=if(cache_status="HIT" AND (response_body="*attacker*" OR response_headers="*x-forwarded-host*"),1,0) | where suspicious=1 | stats count values(url) by clientip, cache_key
The defender's move

Fix the decision, then prove it stays fixed

  • Include every response-changing input in the cache key or Vary header.
  • Do not cache authenticated or personalized responses.
  • Normalize and strip untrusted headers at the edge.
Vulnerable patternnginx
proxy_cache_key "$scheme$host$request_uri";
proxy_cache_valid 200 1h;
# origin still trusts X-Forwarded-Host
Safer patternnginx
proxy_cache_key "$scheme$host$request_uri$http_accept_encoding";
proxy_cache_bypass $cookie_session;
proxy_no_cache $cookie_session $upstream_http_set_cookie;
proxy_set_header X-Forwarded-Host "";
add_header Cache-Control "private, no-store" always;

Cache only responses that are identical for every user with the same key. Strip unkeyed inputs at the edge and never cache responses that set cookies or contain user data.

Regression tests a reviewer would ask for

Unkeyed header

GivenThe CDN caches a page by path

WhenA request adds X-Forwarded-Host

ThenThe header is stripped and the response is unchanged

Second client

GivenA response is cached after a suspicious request

WhenA clean client requests the same path

ThenIt receives the canonical response, not the poisoned one

Personalized response

GivenA page includes the user's name or CSRF token

WhenIt is requested by two users

ThenThe cache does not store or serve the personalized body

Error caching

GivenThe origin returns a 404 or 500

WhenThe cache stores it

ThenError responses are not cached or are keyed safely

False positives

What this finding is not

Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.

  • A header changes the response for your request only: check whether a second client receives the same poisoned body.
  • The cache returns a miss every time: your request may bypass the cache due to cookies or cache-control.
  • A query parameter is reflected: it may be keyed or excluded from caching; verify with a clean cache and a second client.
  • The poisoned response has a short TTL: it can still affect many users during that window.
Working vocabulary

Terms you should be able to use precisely

Cache key
The set of request attributes used to identify a stored response.
Unkeyed input
A request value that affects the response but is not part of the cache key.
Cache poisoning
Storing an attacker-influenced response so other users receive it.
Cache deception
Tricking a cache into storing a personalized response under a public URL.
Fat GET
A GET request with a body that different layers may or may not include in the key.
Cache purge
Removing stored objects, often used as incident response.
Interview drill

Answer these without reciting a payload

What is the root cause of cache poisoning?

A disagreement between the cache key and the inputs that affect the origin response. An unkeyed input lets one response be served to users who did not send it.

How do you verify a cache poisoning finding?

Confirm the response is stored under a shared key, then request the same key from a second clean client and observe the poisoned body. Do not rely on reflection alone.

Why are personalized pages dangerous to cache?

A shared cache can serve one user's data or CSRF token to another. Cache only responses that are identical for every user with that key.

Knowledge check

Can you separate the mechanism from the payload?

Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.

4 questions
01A header changes the page but is absent from the cache key. What is the risk?
02Which response is safest to cache publicly?
03Why is a single request sometimes enough?
04What should the edge do with X-Forwarded-Host?
الخلاصة الموسّعة
لماذا هذا مهم؟

تسميم ذاكرة التخزين المؤقت يحدث عندما تختلف مصادر الحقيقة: الذاكرة تعتقد أن الصفحة واحدة، والأصل يبنيها من مدخل لم يكن جزءًا من المفتاح.

طلب واحد قد يكفي إذا كان المفتاح مشتركًا. لذلك لا تسمح لرؤوس مثل X-Forwarded-Host بالتأثير على الاستجابة، ولا تخزّن صفحات شخصية أو أخطاء أو تحويلات تعتمد على Host. اختبر دائمًا بعميل ثانٍ نظيف، لأن انعكاس القيمة في استجابتك وحدها لا يثبت التسميم.

Which inputs changed the response but not the cache key?