Skip to main content
Security guideReviewed

Web cache poisoning: when one request changes the page every visitor gets

A cache in front of your site keeps one copy of a page and hands it to everyone who asks for the same address.

If a request can change that copy through an input the cache does not look at, everyone gets the changed copy. This guide covers cache keys and unkeyed inputs, the three fixes, how to test without touching real visitors, and a lab you can run on your own computer.

Cache-key inventory and local poisoning lab

An illustration written for this page, for learning and for checking a cache you own. Part A lists what goes into your cache key and what reaches your origin outside it.

How to use it

Part B is a local origin and caching proxy in Node.js, bound to 127.0.0.1, with the stored entries before and after each request and a regression test for each fix, exactly as run on Node.js 26.0.0.

web-cache-poisoning.txt

Introduction2 lines

WEB CACHE POISONING LAB: CACHE-KEY INVENTORY AND LOCAL REVERSE-PROXY EXPERIMENT (VERSION 1) An illustration written for this page, for learning and for checking a cache you own. Part B runs only on your own computer: both programs listen on 127.0.0.1 and send nothing to any other machine. Do not point these steps at a site or a shared CDN you do not have authority over. Testing a live cache can store a changed response that real visitors are then served, so on a real system test only with the owner's authority, on a cache key no visitor uses, and within the host's or CDN's testing terms.

What web cache poisoning is

A site behind a content delivery network (CDN) or a caching reverse proxy has copies of its pages held between the server and the visitor.

RFC 9111, the current HTTP caching standard, calls this a shared cache: one that stores responses for reuse by more than one user. A stored copy that is still fresh can be reused without checking with your server, so the visitor is answered from the copy.

Web cache poisoning is the attack on that arrangement. RFC 9111 section 7.1 says storing malicious content in a cache can extend the reach of an attacker to affect multiple users, and that cache poisoning happens when an attacker uses implementation flaws, elevated privileges or other techniques to insert a response into a cache.

It adds that this is especially effective when shared caches are used to distribute malicious content to many clients. MITRE catalogues the general attack as CAPEC-141 Cache Poisoning: an attacker exploits the functionality of cache technologies to cause specific data to be cached that aids the attacker's objectives.

CAPEC-141 also covers browser caches and public caches such as DNS and ARP caches. This page is about the HTTP caches in front of websites.

In plain terms: someone sends one request that makes your server produce a changed page, the cache keeps that page as the normal copy, and every visitor who asks for the same address is served it until the copy expires or someone clears it.

James Kettle's paper Practical Web Cache Poisoning, published by PortSwigger Research on 9 August 2018, puts the objective as sending a request that causes a harmful response that gets saved in the cache and served to other users.

Cache keys and unkeyed inputs

A cache needs a rule for deciding that two requests are asking for the same thing.

That rule is the cache key. RFC 9111 section 2 defines it as the information a cache uses to choose a response, composed from, at a minimum, the request method and target URI used to retrieve the stored response. The same section notes that many HTTP caches in common use today only cache GET responses and therefore only use the URI as the cache key.

Of the request itself, section 4 asks a cache to compare three things before it reuses a stored response: the target URI, whether the method allows reuse, and any request headers the stored response nominated through its Vary header. Section 2 also lets a cache add material of its own to the key, so the full list depends on the product.

That is where the risk sits. An unkeyed input is any part of a request that reaches your server and changes the response but is not part of the cache key. The 2018 paper states the consequence in one line: any difference in the response triggered by an unkeyed input may be stored and served to other users.

In its first case study, the application used the X-Forwarded-Host request header to build an Open Graph URL in a meta tag, and the cache in front of it did not key on that header.

The weakness underneath has a name of its own. MITRE's CWE-349, Acceptance of Extraneous Untrusted Data With Trusted Data, describes a product that, when processing trusted data, accepts any untrusted data that is also included with the trusted data, treating the untrusted data as if it were trusted. CAPEC-141 lists CWE-349 among its related weaknesses, and the Next.js advisory described further down is classified under it.

Why one stack keys a header and another does not

Which inputs go into the key is a product decision, and the defaults differ.

A header list copied from someone else's CDN describes their stack, not yours. Three products show the range.

  • nginx as a reverse proxy cache: its proxy module documentation gives the default cache key as the scheme, the proxied host and the request URI. Its proxy_pass_request_headers setting, on by default, passes the header fields of the original request to the server behind it. With those defaults, a request header such as X-Forwarded-Host reaches your application without being part of the key.
  • Cloudflare: its cache key documentation lists the default key as the full URL (scheme, host, and URI with query string), the Origin header sent by the client, three method-override headers, and the x-forwarded-host, x-host, x-forwarded-scheme (unless http or https), x-original-url, x-rewrite-url and forwarded headers. Its origin cache control page says that by default Cloudflare does not consider Vary values in caching decisions, and lists where it does: when the Cache Rules Vary setting is configured, when Vary for Images is configured, and when the header is Vary: accept-encoding.
  • Amazon CloudFront: the key and what reaches the origin are set by two separate policies. The cache policy controls the key. The origin request policy, in AWS's words, specifies the information you want to include in origin requests but not include in the cache key, and everything in the cache key is automatically included in origin requests. Beyond the URL path, the request body and the headers CloudFront adds to every origin request, query strings, headers and cookies are not sent to the origin by default, except under legacy cache settings, which forward headers by default.

What the comparison tells you

Read across the three and the same header can be keyed, unkeyed, or not forwarded at all, depending on the product and its settings. A CloudFront origin request policy is a documented way to create an unkeyed input on purpose, which is fine when the origin does not change its response for that input and a problem when it does.

The inventory in part A of the lab on this page is how you find out which applies to your site, one input at a time.

What a poisoned cache entry can do

The damage depends on what the unkeyed input controls.

In the 2018 paper's case studies, unkeyed headers were used to inject script into pages and to point script imports at an attacker's domain. The paper also makes a point worth keeping in mind when findings are triaged: many of its case studies exploit secondary vulnerabilities such as cross-site scripting in the unkeyed input, and without cache poisoning such vulnerabilities are useless, as there is no reliable way to force another user to send a custom header on a cross-domain request. The cache supplies that missing step.

Poisoning does not need script to cause harm. RFC 9111 section 2 notes that caches can store redirects and negative results such as 404 (Not Found) as well as ordinary pages, so a poisoned entry can be a broken redirect or an error page. CAPEC-141 adds that until the cache is refreshed, most applications or clients will treat the corrupted cache value as valid.

A framework example: CVE-2026-44572 in Next.js

Next.js uses an internal request header, x-nextjs-data, for its own data requests. The advisory for CVE-2026-44572 (GHSA-3g8h-86w9-wvmq), published in the Next.js repository on 6 May 2026, explains that on affected versions an outside client could send that header on a normal request to a path handled by middleware that returns a redirect.

The middleware could then replace the standard Location header with an internal x-nextjs-redirect header, which browsers do not follow. Behind a CDN or reverse proxy that caches 3xx responses without varying on that header, a single request could poison the cached redirect, and later visitors could receive a redirect with no Location header until the entry expired or was purged.

CVE-2026-44572 affects Next.js 12.2.0 to before 15.5.16 and 16.0.0 to before 16.2.5, and is fixed in Next.js 15.5.16 and 16.2.5. Both the GitHub Advisory Database and the Next.js repository rate it low, with a CVSS v3.1 score of 3.7, and list CWE-349.

Its two remedies line up with two of the fixes below. The release stops trusting x-nextjs-data by itself for middleware redirect handling, which removes the input on that path, and the workaround before upgrading is to configure the CDN or reverse proxy to vary its cache key on x-nextjs-data for affected responses, which keys it. The Next.js security guide covers that framework's other advisories.

Cache poisoning prevention: three fixes and what each leaves behind

The 2018 paper ranks the options.

Once unkeyed inputs are found, it says, the ideal solution is to outright disable them; failing that, strip the inputs at the cache layer or add them to the cache key. Purging is the third tool, and it belongs to clean-up rather than prevention. The lab runs one test for each.

Fix 1: remove the input

Removing the input means your application no longer acts on it, or the edge drops it before the request is forwarded. 1 min read

Fix 2: add the input to the key

Keying the input lets the response legitimately depend on it while keeping each version separate. 1 min read

Fix 3: purge the poisoned entry

Purging removes stored entries so the next request goes back to the origin. 1 min read

Keep personal and dynamic responses out of shared caches

The fewer responses a shared cache stores, the fewer it can store wrongly. 1 min read

Cache poisoning testing without touching real visitors

Testing a live cache carries a particular risk: a test request that succeeds stores a changed response, and real visitors are then served it.

The 2018 paper calls accidentally poisoning other visitors a perpetual hazard when auditing a live website. On a real system, test only with the owner's authority, only on a cache key no visitor uses, and only within the host's or CDN's testing terms. The paper describes the technique for the second condition: a cache buster with a fixed value, so caching behaviour can be observed without affecting other users.

  • Start on staging behind the same CDN or proxy configuration as production, or in the local lab on this page.
  • On production, confine every test request to a cache key nobody else requests, such as a query parameter only the test sends. Confirm first that the query string is part of the key: Cloudflare's Ignore Query String cache level, for example, leaves it out, and a test parameter would then separate nothing.
  • Use a marker that does nothing: a plain word that shows up in the response, not script and not a working address.
  • Read the cache status header your product returns on each response, and stop at the first stored marker. One stored entry under a test key is the evidence.
  • Purge the test key when you finish, then request it again to confirm the purge took effect.
  • Check the host's and the CDN's testing terms before you start, and keep a record of who authorised the test.

What the lab is for

The lab is for learning and for checking a cache you own. Do not point its steps at a site you do not own or have authority to test, or at a shared CDN configuration that other customers rely on.

How poisoning differs from cache deception and request smuggling

Web cache poisoning changes what the cache stores: the attacker shapes a response and everyone else receives it.

Web cache deception runs the other way: a cache is tricked into storing a private response meant for one person, such as an account page, which the attacker then requests and reads. RFC 9111 section 7.3 describes the risk behind it: implementation and deployment flaws that might lead to the caching of sensitive information thought to be private.

The 2018 paper says the two should not be confused. Marking responses private or no-store narrows what a shared cache keeps, which matters for both, but the tests differ, and the web cache deception guide covers that attack in detail.

HTTP request smuggling is another route to a poisoned cache. RFC 9111 section 7.1 names exploiting differences in message parsing on proxies and in user agents as one common attack vector for cache poisoning, and CAPEC-141 lists HTTP Request Smuggling (CAPEC-33) among the attack patterns it can follow. The HTTP request smuggling guide covers that technique.

Running the cache poisoning lab

The lab on this page is an illustration you run on your own computer.

It is two small programs that talk only to each other on 127.0.0.1, the address that stays inside your machine: an origin, standing in for your web server, and a caching proxy, standing in for your CDN. It needs Node.js and nothing else, and every entry and result shown in it is the output of the run made for this page on Node.js 26.0.0.

The origin builds the address of its script file from the X-Forwarded-Host request header when one is sent, close to the 2018 paper's first case study, which built an Open Graph URL from the same header. In its vulnerable mode the proxy keys its cache on the method and URL only.

That gap is the whole vulnerability: one request carrying X-Forwarded-Host: cache-lab-marker changes the page, and the proxy stores the changed page under the key every visitor uses. The marker is a plain word standing where a site address would go, not a real address.

Each mode shows the stored entries before and after each request, so you can read what the cache holds rather than infer it.

  • Unkeyed:request 1 stores the marker page, and the ordinary visitor in request 2 is served it from the cache. This is the failure the regression test exists to catch.
  • Strip:the proxy deletes X-Forwarded-Host before forwarding, so the origin builds the normal page and nothing stored contains the marker.
  • Keyed:the proxy adds the header's value to the key. The marker page is stored under a key ending x-forwarded-host=cache-lab-marker, the visitor's request does not match it, and a clean page is stored under the visitor's own key.
  • Purge:the poisoned entry is removed and the next visitor gets a clean page from the origin. The run then purges again and repeats request 1, and the marker comes back, because the cause is still there.

The regression test

The test sends the marker request, purges in purge mode, then makes one ordinary request and checks that the page does not contain the marker. It fails on the unkeyed version and passes on the three fixed versions. That is the shape a test for your own cache should have: it fails on today's configuration, you fix the configuration, and it stays in your suite so that a later change to the CDN or the application that undoes the fix shows up as a failing test.

To check your own stack, fill in the inventory in part A first. Then repeat the same steps against a staging copy behind the same cache configuration, with your own marker word and a test-only cache key, under the testing rules above.

Where a Clever Ops test fits

Clever Ops tests websites, custom web applications and their APIs.

For a Next.js application, caching is one of the areas in the route-by-route matrix described in the Next.js guide. Whatever the stack, when you book a scoping call, say which CDN or reverse proxy sits in front of the site, who controls its settings, and whether a staging copy runs behind the same cache configuration.

If Clever Ops built or hosts your site, the work is a security review rather than an independent test, and the report says who built it and who hosts it.

Frequently asked questions

It is an attack in which one request makes a website produce a harmful or broken response, and a shared cache such as a CDN stores that response and serves it to other visitors. RFC 9111, the HTTP caching standard, describes cache poisoning as inserting a response into a cache, which can extend an attacker's reach to multiple users and is especially effective when shared caches distribute the content to many clients.

A part of the request that reaches your server and changes the response but is not part of the cache key, so the cache treats requests with and without it as the same. The 2018 research used request headers such as X-Forwarded-Host. Whether a given header is keyed depends on your cache: the default nginx key is the scheme, proxied host and request URI, while Cloudflare's default key includes x-forwarded-host and several similar headers.

Not on its own, but it can turn a harmless quirk into a problem. If your application already changes its response based on a request header, a cache that stores that response without keying the header turns one request into a page many visitors receive. The inventory in the lab shows whether your site has such an input.

Only with care, because a test that succeeds stores a changed response that real visitors are then served. Use staging or the local lab where you can. On production, test only with the owner's authority, on a cache key no visitor uses, with a harmless marker word, and within your host's and CDN's testing terms, then purge the test key and confirm the purge.

It clears the poisoned copy, which you should do after any fix, but it does not remove the cause. In the lab, a purge followed by the same poisoning request stores the marker again. A purge also reaches only the cache it is sent to; AWS notes that users might continue to see an old version held locally or in a corporate caching proxy until it expires.

It can, for the headers it names, if your cache acts on it. RFC 9110 says Vary expands the cache key, so a response that names X-Forwarded-Host in Vary may be reused only for requests with the same value, unless the origin validates the reuse. Not every cache acts on Vary by default: Cloudflare's documentation says it does not consider Vary values in caching decisions outside the cases it lists. Confirm the behaviour on staging before you rely on it.

Poisoning changes the response the cache stores, so many people receive the attacker's version. Deception gets a cache to store one person's private response, which the attacker then fetches. The web cache deception guide covers the second attack.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.