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.
In this guide
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 itHide the instructions
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
Part A. Cache-key inventory30 lines
Part B. Local reverse-proxy experiment357 lines
Part C. Reading the results7 lines
Whole template402 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.
PART A. CACHE-KEY INVENTORY
Fill in one row for each input. An input is unkeyed when column 2 says no and columns 3 and 4 both say yes. Each unkeyed input needs one of the fixes in column 5.
Columns: 1 Input | 2 In the cache key? | 3 Reaches the origin? | 4 Changes the response? | 5 Fix: remove, key, or none needed
Inputs to list, at minimum:
Scheme, host and path
The query string, and each parameter separately if your cache keys only some of them
Cookie, and each cookie name your application reads
Authorization
Origin
Accept-Encoding, Accept-Language and User-Agent
X-Forwarded-Host, X-Host, X-Forwarded-Scheme, X-Forwarded-Proto and Forwarded
X-Original-URL and X-Rewrite-URL
X-HTTP-Method-Override, X-HTTP-Method and X-Method-Override
Headers your framework uses internally (Next.js, for example, uses x-nextjs-data)
Headers your CDN or proxy adds before it forwards a request
Any other header your application code reads
Column 2: what goes into the key
1. Find where the key is defined: the cache rules or cache policy in your CDN's dashboard, or the cache key setting in your reverse proxy (proxy_cache_key in nginx).
2. Write down every part it lists. Where the product has a default key, copy the default from its documentation, then apply any rule that changes it for the path you are checking.
3. Note whether the cache acts on a Vary header from your origin, and for which headers.
Column 3: what reaches the origin
4. Read which request headers your CDN or proxy forwards. Some forward the original headers by default and some forward only what a policy lists. Note any header it removes or overwrites.
5. Confirm it on staging, on a test-only path: add a temporary log at the origin that records the names of the request headers it receives, then send one request through the cache with each candidate header set to its own marker word. Every header that appears in the log reached the origin.
Column 4: what changes the response
6. Search your application and framework code for every place a request header, cookie or query parameter is read.
7. On staging, send each request twice, with and without the input, and compare the two responses. Any difference counts: a link, a redirect, a status code, a response header or a single word of text.
PART B. LOCAL REVERSE-PROXY EXPERIMENT
What you need: Node.js, with nothing else to install. The files use built-in modules only and were run for this page on Node.js 26.0.0.
Make an empty folder, save the two files below into it, and run the commands from that folder. The origin builds its script address from the X-Forwarded-Host header. The proxy runs in one of four modes:
unkeyed the key is the method and URL only, so X-Forwarded-Host is unkeyed (the vulnerable version)
strip the proxy deletes X-Forwarded-Host before forwarding (fix 1: remove the input at the edge)
keyed the proxy adds the X-Forwarded-Host value to the key (fix 2: add the input to the key)
purge unkeyed, with the poisoned entry purged before the visitor arrives (fix 3: purge the cache)
File 1 of 2: cache-lab.js
---- start of cache-lab.js ----
"use strict";
// Web cache poisoning lab: an origin and a small caching reverse proxy,
// both bound to 127.0.0.1 on ports the operating system picks.
// An illustration for learning and for checking a cache you own.
// Node.js built-in modules only. Nothing here contacts another machine.
const http = require("node:http");
const SITE = "https://shop.example";
const MARKER = "cache-lab-marker";
const MODES = ["unkeyed", "strip", "keyed", "purge"];
// ORIGIN. It builds its script link from X-Forwarded-Host when one is sent.
function handleOriginRequest(request, response) {
const assetHost = request.headers["x-forwarded-host"] || "shop.example";
const body = "<p>Lab shop</p><script src='https://" + assetHost + "/static/app.js'></script>";
response.writeHead(200, { "content-type": "text/html", "cache-control": "public, max-age=300" });
response.end(body);
}
// CACHE KEY. Method and URL, plus X-Forwarded-Host only in keyed mode.
function buildCacheKey(mode, request) {
const key = request.method + " " + SITE + request.url;
if (mode !== "keyed") return key;
return key + " x-forwarded-host=" + (request.headers["x-forwarded-host"] || "(none)");
}
// HEADERS SENT TO THE ORIGIN. Strip mode removes X-Forwarded-Host at the edge.
function buildOriginHeaders(mode, request) {
const headers = Object.assign({}, request.headers);
delete headers.host;
delete headers.connection;
if (mode === "strip") delete headers["x-forwarded-host"];
return headers;
}
function readMaxAge(cacheControl) {
for (const directive of String(cacheControl || "").split(",")) {
const parts = directive.trim().split("=");
if (parts[0] === "max-age") return Number(parts[1]) || 0;
}
return 0;
}
// STORAGE RULES. Only a 200 response to GET that allows storing for a time.
function isStorable(request, reply) {
const cacheControl = String(reply.headers["cache-control"] || "");
if (request.method !== "GET" || reply.status !== 200) return false;
if (cacheControl.includes("no-store") || cacheControl.includes("private")) return false;
return readMaxAge(cacheControl) > 0;
}
function isFresh(entry) {
return Date.now() - entry.storedAt < entry.maxAge * 1000;
}
function readBody(stream) {
return new Promise(function (resolve, reject) {
let body = "";
stream.setEncoding("utf8");
stream.on("data", function (chunk) { body += chunk; });
stream.on("end", function () { resolve(body); });
stream.on("error", reject);
});
}
function fetchFromOrigin(originPort, request, headers) {
return new Promise(function (resolve, reject) {
const options = { host: "127.0.0.1", port: originPort, method: request.method, path: request.url, headers: headers, agent: false };
const outgoing = http.request(options, function (incoming) {
readBody(incoming).then(function (body) {
resolve({ status: incoming.statusCode, headers: incoming.headers, body: body });
}, reject);
});
outgoing.on("error", reject);
outgoing.end();
});
}
function sendReply(response, reply, cacheStatus) {
const headers = Object.assign({}, reply.headers, { "x-cache": cacheStatus });
delete headers.connection;
delete headers["transfer-encoding"];
response.writeHead(reply.status, headers);
response.end(reply.body);
}
// PROXY. Serves a fresh stored entry, or asks the origin and maybe stores the reply.
function createProxy(mode, originPort, cache) {
return http.createServer(async function (request, response) {
try {
const key = buildCacheKey(mode, request);
const stored = cache.get(key);
if (stored && isFresh(stored)) return sendReply(response, stored, "HIT");
const reply = await fetchFromOrigin(originPort, request, buildOriginHeaders(mode, request));
if (isStorable(request, reply)) {
const entry = Object.assign({ key: key, path: request.url, storedAt: Date.now(), maxAge: readMaxAge(reply.headers["cache-control"]) }, reply);
cache.set(key, entry);
}
sendReply(response, reply, "MISS");
} catch (error) {
response.writeHead(502, { "content-type": "text/plain" });
response.end("Origin unreachable");
}
});
}
// PURGE. Removes every stored entry for one path, the way a CDN purge by URL does.
function purgePath(cache, path) {
let removed = 0;
for (const entry of Array.from(cache.values())) {
if (entry.path === path) {
cache.delete(entry.key);
removed += 1;
}
}
return removed;
}
function listen(server) {
return new Promise(function (resolve) {
server.listen(0, "127.0.0.1", function () { resolve(server.address().port); });
});
}
function stop(server) {
server.closeAllConnections();
return new Promise(function (resolve) { server.close(resolve); });
}
async function startLab(mode) {
if (!MODES.includes(mode)) throw new Error("Unknown mode: " + mode);
const cache = new Map();
const origin = http.createServer(handleOriginRequest);
const originPort = await listen(origin);
const proxy = createProxy(mode, originPort, cache);
const port = await listen(proxy);
return {
port: port,
listEntries: function () { return Array.from(cache.values()); },
purge: function (path) { return purgePath(cache, path); },
close: function () { return Promise.all([stop(proxy), stop(origin)]); },
};
}
// CLIENT. Sends one GET for / to the proxy on 127.0.0.1.
function getPage(port, headers) {
return new Promise(function (resolve, reject) {
const options = { host: "127.0.0.1", port: port, path: "/", headers: headers, agent: false };
http.get(options, function (incoming) {
readBody(incoming).then(function (body) {
resolve({ status: incoming.statusCode, cache: incoming.headers["x-cache"], body: body });
}, reject);
}).on("error", reject);
});
}
function printEntries(label, lab) {
console.log(label + ":");
const entries = lab.listEntries();
if (entries.length === 0) console.log(" (none)");
for (const entry of entries) {
console.log(" key: " + entry.key);
console.log(" body: " + entry.body);
}
}
function describeVisit(label, visit) {
const sawMarker = visit.body.includes(MARKER) ? "YES" : "no";
console.log(label + ": " + visit.cache + ", marker in page: " + sawMarker);
}
async function runDemo(mode) {
const lab = await startLab(mode);
try {
console.log("=== Mode: " + mode);
printEntries("Stored entries before", lab);
describeVisit("Request 1, with X-Forwarded-Host: " + MARKER, await getPage(lab.port, { "x-forwarded-host": MARKER }));
printEntries("Stored entries after request 1", lab);
if (mode === "purge") {
console.log("Purged / (entries removed: " + lab.purge("/") + ")");
printEntries("Stored entries after the purge", lab);
}
describeVisit("Request 2, an ordinary visitor", await getPage(lab.port, {}));
printEntries("Stored entries after request 2", lab);
if (mode === "purge") {
console.log("Purged / again (entries removed: " + lab.purge("/") + "), then request 1 is repeated");
describeVisit("Request 3, with X-Forwarded-Host: " + MARKER, await getPage(lab.port, { "x-forwarded-host": MARKER }));
printEntries("Stored entries after request 3", lab);
}
} finally {
await lab.close();
}
}
async function main() {
const chosen = process.argv.slice(2);
const modes = chosen.length > 0 ? chosen : MODES;
for (const mode of modes) await runDemo(mode);
}
if (require.main === module) {
main().catch(function (error) {
console.error(error);
process.exitCode = 1;
});
}
module.exports = { startLab, getPage, MARKER, MODES };
---- end of cache-lab.js ----
File 2 of 2: cache-lab.test.js
---- start of cache-lab.test.js ----
"use strict";
// Regression test: after one request carrying the marker header, an ordinary
// visitor must not be served the marker. It fails on the unkeyed version and
// passes on each fixed version.
const test = require("node:test");
const assert = require("node:assert/strict");
const { startLab, getPage, MARKER } = require("./cache-lab.js");
async function poisonThenVisit(mode) {
const lab = await startLab(mode);
try {
await getPage(lab.port, { "x-forwarded-host": MARKER });
if (mode === "purge") lab.purge("/");
const visit = await getPage(lab.port, {});
return visit.body;
} finally {
await lab.close();
}
}
const CASES = [
{ mode: "unkeyed", name: "unkeyed version" },
{ mode: "strip", name: "fixed by stripping the header at the edge" },
{ mode: "keyed", name: "fixed by adding the header to the cache key" },
{ mode: "purge", name: "fixed by purging the poisoned entry" },
];
for (const testCase of CASES) {
test(testCase.name + ": an ordinary visitor does not get the marker", async function () {
const body = await poisonThenVisit(testCase.mode);
assert.equal(body.includes(MARKER), false, "the visitor was served: " + body);
});
}
---- end of cache-lab.test.js ----
STEP 1. Run the experiment in all four modes:
node cache-lab.js
To run one mode only, name it, for example: node cache-lab.js keyed
Output seen on Node.js 26.0.0:
=== Mode: unkeyed
Stored entries before:
(none)
Request 1, with X-Forwarded-Host: cache-lab-marker: MISS, marker in page: YES
Stored entries after request 1:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
Request 2, an ordinary visitor: HIT, marker in page: YES
Stored entries after request 2:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
=== Mode: strip
Stored entries before:
(none)
Request 1, with X-Forwarded-Host: cache-lab-marker: MISS, marker in page: no
Stored entries after request 1:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://shop.example/static/app.js'></script>
Request 2, an ordinary visitor: HIT, marker in page: no
Stored entries after request 2:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://shop.example/static/app.js'></script>
=== Mode: keyed
Stored entries before:
(none)
Request 1, with X-Forwarded-Host: cache-lab-marker: MISS, marker in page: YES
Stored entries after request 1:
key: GET https://shop.example/ x-forwarded-host=cache-lab-marker
body: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
Request 2, an ordinary visitor: MISS, marker in page: no
Stored entries after request 2:
key: GET https://shop.example/ x-forwarded-host=cache-lab-marker
body: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
key: GET https://shop.example/ x-forwarded-host=(none)
body: <p>Lab shop</p><script src='https://shop.example/static/app.js'></script>
=== Mode: purge
Stored entries before:
(none)
Request 1, with X-Forwarded-Host: cache-lab-marker: MISS, marker in page: YES
Stored entries after request 1:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
Purged / (entries removed: 1)
Stored entries after the purge:
(none)
Request 2, an ordinary visitor: MISS, marker in page: no
Stored entries after request 2:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://shop.example/static/app.js'></script>
Purged / again (entries removed: 1), then request 1 is repeated
Request 3, with X-Forwarded-Host: cache-lab-marker: MISS, marker in page: YES
Stored entries after request 3:
key: GET https://shop.example/
body: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
STEP 2. Run the regression test on all four versions:
node --test cache-lab.test.js
Output seen on Node.js 26.0.0. Timings differ on every run, and the stack trace and error details printed under the failure are left out here:
✖ unkeyed version: an ordinary visitor does not get the marker (14.242ms)
✔ fixed by stripping the header at the edge: an ordinary visitor does not get the marker (2.194625ms)
✔ fixed by adding the header to the cache key: an ordinary visitor does not get the marker (2.156792ms)
✔ fixed by purging the poisoned entry: an ordinary visitor does not get the marker (1.590667ms)
ℹ tests 4
ℹ suites 0
ℹ pass 3
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 103.19475
✖ failing tests:
test at cache-lab.test.js:30:3
✖ unkeyed version: an ordinary visitor does not get the marker (14.242ms)
AssertionError [ERR_ASSERTION]: the visitor was served: <p>Lab shop</p><script src='https://cache-lab-marker/static/app.js'></script>
true !== false
Exit code 1: the test fails on the unkeyed version and passes on the three fixed versions.
STEP 3. Run the regression test on the fixed versions only:
node --test --test-name-pattern=fixed cache-lab.test.js
Output seen on Node.js 26.0.0:
✔ fixed by stripping the header at the edge: an ordinary visitor does not get the marker (13.599ms)
✔ fixed by adding the header to the cache key: an ordinary visitor does not get the marker (2.216542ms)
✔ fixed by purging the poisoned entry: an ordinary visitor does not get the marker (2.307916ms)
ℹ tests 3
ℹ suites 0
ℹ pass 3
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 98.86625
Exit code 0.
PART C. READING THE RESULTS
unkeyed Request 1 stores the marker page under the key every visitor uses. Request 2 is an ordinary visitor with no special header, and the cache serves it the marker page (HIT). This is web cache poisoning.
strip The marker header does not reach the origin, so no stored entry contains the marker. This is the only mode in which the marker page is not produced at all.
keyed The marker page is still produced and stored, but under a key that only a request carrying the same header value matches. The visitor misses that entry and gets a clean page stored under its own key.
purge The purge removes the poisoned entry and the visitor gets a clean page from the origin. After a second purge, the same marker request stores the marker page again: purging clears an entry but leaves the cause in place.
Adapting the test to your own stack
Keep the one assertion: after a request carrying the marker header, an ordinary request for the same address does not contain the marker. Point it at a staging copy behind your real cache configuration, with your own marker word and a test-only cache key. Run it before the fix and record that it fails, then keep it in your test suite once the fix makes it pass.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.
Removing the input means your application no longer acts on it, or the edge drops it before the request is forwarded. In the application, that is a code or configuration change, such as building absolute URLs from a configured site address instead of a request header.
At the edge, nginx documents the mechanism: when proxy_set_header sets a header field to an empty string, that field is not passed to the server behind it. On CloudFront, outside legacy cache settings, a viewer header left out of both the cache policy and the origin request policy is not sent to the origin by default, apart from the headers CloudFront adds to every origin request, such as Host and User-Agent.
The paper calls this the ideal solution, and in the lab it is the only mode in which no stored entry contains the marker. Its weakness is coverage. The paper warns that it is hard to know whether other layers and frameworks are sneaking in support for extra headers, which is why the inventory asks for every input that reaches the origin, not only the ones you expect.
Keying the input lets the response legitimately depend on it while keeping each version separate. In HTTP, the origin says so with the Vary header. RFC 9110 section 12.5.5 says a Vary field listing header names tells caches that they MUST NOT use the response to satisfy a later request unless the later request has the same values for the listed header fields as the original request, or reuse has been validated by the origin; in other words, Vary expands the cache key. RFC 9111 section 4.1 sets out the same matching rule from the cache's side.
Two cautions apply. First, your cache has to act on Vary for this to work. Cloudflare's documentation says it does not consider Vary values by default outside the cases it lists, so on that product the header is keyed through a Cache Rule instead.
Second, every keyed header splits the cache. AWS notes that including fewer values in the cache key increases the likelihood of a cache hit, and Cloudflare that custom cache keys may reduce your cache hit rate and result in cache sharding.
In the lab, the marker page is still stored, but under a key that only a request with the same header value matches, so the ordinary visitor gets a separate clean entry.
Purging removes stored entries so the next request goes back to the origin. RFC 9111 section 4.4 covers invalidation as a side effect of unsafe requests such as PUT, POST or DELETE; clearing an entry on demand is done through your product's own feature.
CloudFront calls it invalidation. Cloudflare recommends purging a single file by URL among several options. In nginx, the proxy_cache_purge directive is available as part of the commercial subscription.
Two limits follow. A purge reaches only the cache it is sent to: AWS notes that after an invalidation, a user with a version cached locally or behind a corporate caching proxy might continue to see the old version until it expires there, and RFC 9111 section 4.4 says a state-changing request only invalidates responses in the caches it travels through.
And a purge does not remove the cause. Cloudflare advises verifying a purge by requesting the asset again and confirming that its CF-Cache-Status header no longer reads HIT.
The lab's purge run goes one step further: after a second purge it repeats the poisoning request, and the marker is stored again. Purge after any fix, and treat a purge on its own as clean-up rather than a closed finding.
The fewer responses a shared cache stores, the fewer it can store wrongly. RFC 9111 section 5.2.2.7 says the unqualified private directive indicates that a shared cache MUST NOT store the response, and section 5.2.2.5 says no-store indicates that a cache MUST NOT store any part of either the request or the response.
Section 7.3 adds that a Set-Cookie header does not stop a response being cached. The 2018 paper's own advice is that restricting caching to purely static responses is also effective, provided you are sufficiently wary about what you define as static.
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.