Skip to content

Web Cache Poisoning: How It Works and How to Defend

Learn how web cache poisoning works, why a cache buster can fail on hidden framework caches, and the defences that reduce your exposure.

Technology Cyber Security 6 min read Add as preferred source
Editorial illustration of stacked translucent layers filtering a stream of data packets, with one packet glowing red among the clean ones
Editorial illustration of stacked translucent layers filtering a stream of data packets, with one packet glowing red among the clean ones

Web cache poisoning is an attack in which someone manipulates a web server and its cache so that a harmful response is stored and then served to other users[1]. The cache becomes a distribution channel: the attacker does the hard part once, and every visitor who matches that cached entry receives the payload.

This post explains the mechanics in plain terms, covers a recent argument that your CDN may not be the only cache you need to worry about[2], and ends with a defence checklist you can apply to your own stack.

A web cache sits between your server and your users. It saves responses for a period of time, and when an equivalent request arrives it answers from the saved copy instead of bothering the back end[1]. That saves load and speeds up pages.

The attack has two phases. First, the attacker works out how to make the back end produce a response containing something dangerous. Second, they make sure that response gets cached and served to the intended victims[1]. The payload can be anything from cross-site scripting (XSS) to JavaScript injection or an open redirect[1].

PortSwigger’s research popularised the technique in 2018 with the paper “Practical Web Cache Poisoning”, and extended it in 2020[1].

The cache compares a predefined subset of each request, called the cache key. Typically that means the request line and the Host header[1]. Everything else in the request is unkeyed, meaning the cache ignores it when choosing whether to serve a stored copy[1].

This is the root of the problem. If the server uses an unkeyed input (often a header) to build the response, an attacker can change the response without changing the cache key. The poisoned copy is then served to everyone whose request matches that key[1].

At a high level, PortSwigger describes three steps[1]:

  1. Identify unkeyed inputs. Add random inputs to requests and watch whether the response changes. Tools such as Param Miner automate guessing headers[1].
  2. Elicit a harmful response. If the input is reflected without sanitising, or used to generate other data, it is a possible entry point[1].
  3. Get the response cached. Whether a response is stored can depend on file extension, content type, route, status code and response headers[1].

The impact depends on two things: how harmful the injected payload is, and how much traffic the affected page gets. A poisoned home page of a major site could reach thousands of users with no further action from the attacker[1].

When testing a live site, PortSwigger advises adding a cache buster, such as a unique query parameter, so your requests get their own cache key and cannot be served to real users[1].

Security researcher Amr Elsagaei argues this habit has a blind spot. In his write-up, a modern framework can run its own response cache behind the CDN, storing rendered pages on disk. That cache does not advertise itself with the usual X-Cache or Age headers[2]. The CDN keys on the full URL, but the framework cache, in the Next.js case he examines, keys on the pathname, so a query-string buster never reaches the second key[2].

Two limits matter here. The effect applies to routes that end up in that inner cache without being designed for it, not to every route on the internet[2]. And this is one researcher’s analysis of one framework; treat it as a warning to test your own stack, not as a universal rule.

According to the same write-up, one unauthenticated request header could pull a no-store route into the Next.js framework cache and hand its response to the next requester. The issue is tracked as CVE-2024-46982 and was fixed in Next.js 13.5.7 and 14.2.10 in September 2024[2][3]. It affected non-dynamic, server-rendered routes in the Pages Router, not dynamic [slug] routes and not the App Router[2].

Two details are worth remembering as a defender:

  • It survives the usual clean-up. The stored entry lives in the build output on disk, so purging the CDN or restarting the app does not remove it. Per the write-up, discarding the build output and rebuilding does[2].
  • The patch filtered the input rather than removing the trust. The author notes the framework code still trusts the header, and the fix strips it earlier in a separate layer[2]. That is a reminder that a filter is only as complete as its list.

If you run Next.js, upgrade to a patched release and read the official advisory[3].

The write-up also describes a chain that needs no framework bug at all. It depends on two conditions, neither a vulnerability on its own[2]:

  1. The application mirrors inbound request headers onto its responses, often to keep trace or correlation IDs. This is an application-level mistake[2].
  2. The cache in front ignores Vary. Frameworks use Vary to tell caches which request headers change the content, but a cache keyed on method plus URL never reads it[2].

Together they let an outsider influence response labels such as Content-Type and Cache-Control. The author’s broader lesson is useful beyond Next.js: some output is left unescaped because its declared type makes escaping seem pointless, so if an attacker can change the label, the missing escaping suddenly matters[2]. The chain is credited in the write-up to research by Rachid Allam, published in June 2026[2].

PortSwigger’s guidance is the best starting point[1]:

  • Question whether you need caching at all. If it was switched on by default when you adopted a CDN, check that the defaults match your needs[1].
  • Cache only static responses, and be strict about what counts as static[1].
  • Disable headers you do not need. Many poisoning bugs rely on obscure request headers that the site never required[1].
  • Rewrite instead of excluding from the key. If you drop something from the cache key for performance, rewrite the request[1].
  • Do not accept fat GET requests (a GET with a body)[1].
  • Patch client-side bugs even if they look unexploitable. Cache quirks can make them exploitable[1].

From the framework-cache research, add these[2]:

  • Never echo arbitrary request headers into responses. Allowlist the specific tracing headers you need.
  • Check whether your cache layer honours Vary before relying on it for correctness.
  • When you find a poisoned entry, purge every layer, including any framework-level cache, not only the CDN.
Layer Question to ask Source
CDN or edge cache What is in the cache key, and does it respect Vary? [1][2]
Framework response cache Which routes can it store, and how is its key built? [2]
Application code Does it reflect request headers or inputs into responses? [1][2]
Operations Does your purge procedure reach every cache layer? [2]
Cross-section illustration of three stacked layers between a browser and a server, with a small glowing packet passing through only the middle layer
One response can pass through several caches, and only the outermost one tends to announce itself.

  1. ^ a b c d e f g h i j k l m n o p q r s t u v w PortSwigger Web Security Academy. “Web cache poisoning”. PortSwigger Ltd. https://portswigger.net/web-security/web-cache-poisoning
  2. ^ a b c d e f g h i j k l m n o p q r Elsagaei, Amr. “Cache Poisoning: The Cache You Can’t Purge”. 12 September 2026 (modified 15 September 2026). https://amrelsagaei.com/cache-poisoning-the-cache-you-cant-purge
  3. ^ a b Vercel. “Next.js cache poisoning advisory” (GHSA-gp8f-8m3g-qvj9, CVE-2024-46982). GitHub. https://github.com/vercel/next.js/security/advisories/GHSA-gp8f-8m3g-qvj9

Frequently asked questions

What is web cache poisoning?

It is an attack where someone gets a web server and its cache to store a harmful response, so the cache serves that response to other users. It has two phases: eliciting a dangerous response, then getting it cached.

What is an unkeyed input in caching?

An unkeyed input is any part of a request, such as a header, that the cache ignores when deciding whether two requests are equivalent. If the server still uses that input to build the response, an attacker can use it to inject a payload.

What does a cache buster do, and why can it fail?

A cache buster is a unique parameter added to a request so your test is stored under its own cache key and never reaches real users. It can fail when a second cache behind the CDN keys only on the path, because the parameter is then ignored there.

How do I reduce my exposure to web cache poisoning?

Cache only truly static responses, disable request headers you do not need, never reflect arbitrary request headers into responses, avoid fat GET requests, and keep frameworks patched. If you must leave something out of the cache key, rewrite the request instead.

You're offline Check your connection.