Web cache poisoning: when the cache keeps what one request made up

Web cache poisoning is an attack in which one request gets a harmful response stored in a shared cache, so that later visitors receive it from the cache instead of from your application. It works because a cache compares only part of a request when it decides whether it already holds an answer. Anything the application reads from the rest of the request is an input the cache does not see.

Section Web attacks Updated Standard RFC 9111

Quick facts

Cache key
At minimum the request method and the target URI (RFC 9111 section 2)
Unkeyed input
A part of the request the cache ignores when matching, but the application still reads
Two steps
Get the origin to return a harmful response, then get that response cached (PortSwigger Web Security Academy)
Research
Practical Web Cache Poisoning (2018) and Web Cache Entanglement (2020), PortSwigger Research
Related
OWASP: Cache Poisoning, an older article built on response splitting
Main fix
Do not cache what you do not need to, and never let an input outside the cache key change a cached response

Definitions follow RFC 9111 (HTTP Caching) and the PortSwigger Academy topic; defences are checked against both. RFC 9111 itself calls the attack “cache poisoning” in its security considerations (section 7.1).

The cache key and what it leaves out

A shared cache stores a response and answers later requests with it. To decide whether a stored response fits a new request, the cache builds a cache key. RFC 9111 says the key is composed, at a minimum, of the request method and the target URI. Caches add other parts of the request when the response varies with them, and that is the job of the Vary response header. The mirror case, where a private page is stored, is web cache deception.

How Vary widens the key

If a response carries Vary: Accept-Encoding, the cache may reuse it only for requests whose Accept-Encoding matches the original. Without a match, section 4.1 of the RFC says the cache must not use the stored response without revalidating it. A Vary value of * never matches, so such a response is effectively never reused. MDN describes the same mechanism in its Vary reference.

Where the gap opens

The key is the cache’s idea of which request parts matter. The application has its own idea. If the application builds a response from a header that appears neither in the key nor in Vary, two requests that the cache treats as identical can produce different responses, and the cache will serve whichever it stored first. PortSwigger calls such a header an unkeyed input.

Typical candidates are forwarding headers set by proxies, such as X-Forwarded-Host, along with cookies, query parameters the cache is told to strip, and request bodies on methods the cache treats as bodyless. The reverse proxy in front of your application often adds or rewrites some of these, which is why the application can come to trust them.

How poisoning works

Web cache poisoning needs two things at once: an application that reflects or acts on an unkeyed input, and a cache that stores the result. The Academy describes the attack in two phases. First the attacker finds a way to make the origin return a response containing something harmful. Then they make sure that response is cached and served to the intended victims.

A common shape: a page includes an absolute URL for a script or an image, and the application builds that URL from a header the cache does not key. The attacker sends a request for a popular page with a header value pointing at a domain they control. The origin writes it into the page, the cache stores the page under the ordinary key, and every visitor who asks for that URL during the cache lifetime loads the attacker’s resource. The attacker sends one request; the cache delivers it many times.

The harm depends on what the response contains. A reflected value that would only affect the attacker’s own browser as cross-site scripting becomes stored for everyone. A poisoned redirect sends visitors elsewhere. A poisoned error page, cached by mistake, can take a page down for the cache lifetime without any flood of traffic.

Parsing differences are a second route

RFC 9111 names one common vector: differences in message parsing between proxies and user agents. That is the territory of HTTP request smuggling, where a cache and an origin disagree on where a request ends. Older poisoning cases used header injection and response splitting; the OWASP article is built on those, and the same flaw is covered under CRLF injection. Modern frameworks refuse line breaks in header values, so unkeyed inputs are now the more discussed route.

Poisoning versus cache deception

The two names are close and the attacks are opposites. In poisoning, the attacker causes a harmful response to be stored and served to others. In web cache deception, the attacker tricks the cache into storing a victim’s private response, then fetches that stored copy. The Academy puts the cause of deception in a mismatch between how the cache and the origin interpret a request, for instance whether a URL points at a static file.

The two attacks side by side
Web cache poisoningWeb cache deception
What gets storedA response made harmful by attacker-controlled inputA private response meant for one victim
Who is harmedLater visitors who receive the stored responseThe victim whose data was stored
Root causeAn input the cache ignores but the application usesA cache and an origin that read the same URL differently
Main fixKey or remove the input; limit what is cacheableMark private responses no-store or private

How it gets found

Testers look for two facts: which parts of a request change the response, and whether the cache keys them. Burp Suite’s Param Miner extension automates the search for unkeyed headers; the Academy links it from its poisoning topic. Anyone testing a live site has to avoid caching their own experiments for other people, which is why the usual advice is to test on a staging copy or to add a unique value to the key, such as a random query parameter, so the response lands in an entry no one else uses.

From the defender’s side the questions are simpler. Which of your pages are cacheable? Which request headers does the application read when building them? Is each of those headers in the key, listed in Vary, or ignored? Responses that fail that audit are the ones to change first. Security headers are a separate check and do not answer it.

How to prevent web cache poisoning

The Academy’s advice starts from a plain rule: disabling caching where it is not needed is the most definitive fix. The steps below follow its recommendations and RFC 9111.

  1. Cache only what is static. Restrict caching to genuinely static responses, and check that no request can make the origin fetch a bad version of a static file.
  2. Keep dynamic and personal pages out. Send Cache-Control: no-store (a cache must not store any part of the exchange) or private (a shared cache must not store the response) on them.
  3. Account for every header the application reads. If a header changes the response, add it to the cache key or list it in Vary. Use the same Vary value on every response for a URL, including 304 responses.
  4. Do not reflect headers you do not need. Build absolute links from configured values rather than from X-Forwarded-Host or the request Host; see host header injection for the related risk.
  5. Disable unused cache features. The Academy suggests auditing which unkeyed headers your CDN or cache supports and turning off those you do not use.
  6. Rewrite instead of excluding. If you drop something from the key for performance, rewrite the request so the application never sees it.
  7. Refuse “fat” GET requests where you do not need them, and patch client-side flaws even when they look unexploitable.

Varying on too many headers has a cost: each distinct value can create a separate cache entry, so a long Vary list lowers the hit rate. It is a trade-off to weigh, not a free fix. A CDN or reverse proxy is often the shared cache in this picture. How it builds its keys is described in that product’s own documentation; this page makes no claim about the cache behaviour of Bridge CDN.

Where a WAF helps and where it does not

A WAF sees each request as it arrives and can match it against rules. That helps in a few places. A request carrying a forwarding header with a value your application should never receive, or a header that contains encoded line breaks or script, can be flagged. If you know the host names your site answers for, requests with a different Host can be refused.

It helps less than it seems, for reasons that follow from how the attack works.

  • The harm happens on later requests. The visitors who receive the poisoned response send ordinary requests that match no rule, and a cache hit may be answered before the filter ever sees it, depending on where the cache sits.
  • The filter cannot see the cache key. It does not know which headers your cache keys or which ones the application reflects, so it cannot tell a harmless header from a dangerous one.
  • The fix is in headers and caching rules. Keying, Vary and Cache-Control belong to the application and the cache configuration. A rule can narrow the entry points, not close the gap.

Bridge WAF works in three modes. In monitor, matches are recorded and every request is still served, so the activity log shows which requests carry unusual header values before anything is refused. Start there, read the log, and only then move a rule to block. Expect some matches to be legitimate traffic; the page on false positives covers how to review them, and monitor mode explains the workflow.

Questions

What is web cache poisoning?

Web cache poisoning is an attack in which an attacker gets a harmful response stored in a shared cache, so other users receive it. It exploits inputs the cache ignores when matching requests but the application still uses to build the response.

What is the difference between cache poisoning and cache deception?

Poisoning stores a harmful response and serves it to other users. Deception tricks the cache into storing a victim’s private response, which the attacker then retrieves. Poisoning harms later visitors; deception exposes the victim’s own data.

What is a cache key?

A cache key is the set of request parts a cache uses to decide whether a stored response matches a new request. RFC 9111 defines it as composed, at a minimum, of the request method and target URI. The Vary header adds further request headers.

How do you prevent web cache poisoning?

Cache only static responses, mark dynamic and personal pages no-store or private, include every header that changes a response in the cache key or in Vary, and do not build links or content from headers outside the key. Disabling caching where it is not needed is the most definitive fix.

Can a WAF stop web cache poisoning?

Only in part. A WAF can flag or refuse requests with unexpected header values, but it cannot see the cache key or the visitors who later receive the stored response. The lasting fix is in caching rules and in how the application uses headers.