Web cache deception: when a shared cache keeps one person's private page
A cache in front of your site stores copies of responses so it can answer the next visitor without asking your server.
Web cache deception is the case where it stores the wrong one: a signed-in person's private page, kept under an address the cache took for a public file and handed to the next request, session or no session. This guide explains how a shared cache decides what to store, why one URL can mean two things to two layers, and the four controls that stop it. It comes with a response-cache matrix, four path-confusion fixtures and a lab you can run on your own computer.
In this guide
Response-cache matrix, path-confusion fixtures and lab
Part 1 is a matrix with six route types, from a public static file to an error page: who may see each, the Cache-Control and Vary to send, whether a shared cache may store it, the cache status to expect and what an anonymous request must get back, with the source named where a value rests on one. Part 2 gives four path-confusion fixtures.
How to use itHide the instructions
Parts 3 and 4 are an illustration you can run with Node.js and no installs: an invented origin behind a cache written for this page, each in a careless and a careful version, with every output copied from one recorded run on Node.js 26.0.0. Parts 5 and 6 are browser checks and a regression test for your own application.
web-cache-deception.txt
Introduction17 lines
Part 1: The response-cache matrix124 lines
Part 2: The four path-confusion fixtures37 lines
Part 3: The lab files690 lines
Part 4: The recorded run480 lines
Part 5: Browser checks on your own application30 lines
Part 6: The same regression test on your own application7 lines
Whole template1,421 lines
RESPONSE-CACHE MATRIX, PATH-CONFUSION FIXTURES AND LAB
ILLUSTRATION ONLY. Parts 1, 2, 5 and 6 are for your own application. Parts 3 and 4 are a lab: an invented origin, Lab Ledger, and a small shared cache written for this page, held in memory and run on one computer. Nothing in the lab is a client's system or a client's result. It shows the pattern, not how any real CDN, proxy or framework decides what to store, and its cache is not an implementation of RFC 9111. The one account, lab-member, its password invented-lab-password-not-real and the private marker were made up for this page and are no product's default. Use what the lab teaches only on systems you own or are authorised in writing to test, signed in as your own test account.
WHAT THE LAB NEEDS
Node.js. Apart from each other, the eight files import only node:assert/strict, node:crypto, node:http and node:test, and the lab installs no packages. The run in Part 4 was recorded on macOS with Node.js 26.0.0, the only version and the only system it was run on. Test timings, the port and the process id differ from run to run.
WHAT THE LAB DOES NOT DO
Both servers listen on 127.0.0.1, on ports the system picks, and no request leaves your computer. Nothing is written to disk: sessions and stored responses are held in memory and are gone when a script ends. The run scripts and the test start their own servers and stop them before they finish. Only serve.mjs keeps running, until you stop it. The session cookie's value is random and is never printed. There is no browser in the lab: its anonymous visitor is a second request that the script sends with no cookie.
WHAT IS HERE
Part 1 The response-cache matrix: six route types to fill in for your own application
Part 2 The four path-confusion fixtures, and how to build them for your own routes
Part 3 The lab files: eight files
Part 4 The recorded run: nine commands and what each printed
Part 5 Browser checks on your own application
Part 6 The same regression test on your own application
================================================================
PART 1: THE RESPONSE-CACHE MATRIX
================================================================
How to use it
Put every route of your application under one of the six rows. For each route, write down what you observe: the Cache-Control and Vary headers on the response, your cache's status header on a first and a second request, and what a request with no session gets back. Compare each with the expected value. Part 5 has the browser steps. Where an expected value rests on a source, the cell names it. Every other expected value is this page's advice, whether or not the cell says so. Section numbers are from RFC 9111 unless another document is named.
Two rules apply to every row. The last line decides: if a request with no session receives anything that belongs to a signed-in person, the route fails, whatever the headers say. And every check is made with your own test account, holding invented data, on an application you own or are authorised in writing to test.
ROW 1: A PUBLIC STATIC FILE
A stylesheet, script, font or image that is the same for everyone.
Who may see it
Anyone.
Cache-Control the origin should send
public, with a max-age, and an s-maxage where the shared cache should keep the file for a different time. Section 5.2.2.9: public indicates that a cache MAY store the response even if it would otherwise be prohibited, subject to the constraints in section 3. Section 5.2.2.10: for a shared cache, s-maxage overrides the maximum age given by max-age or the Expires header field. Which values to use is this page's advice. A framework may set the header for you: the Next.js documentation says Next.js sets public, max-age=31536000, immutable on truly immutable assets and that it cannot be overridden.
Vary
Only the request headers that change the bytes sent. Naming those and no others is this page's advice. RFC 9110 section 12.5.5: an origin server SHOULD generate Vary on a cacheable response when it wishes that response to be selectively reused. Its own example names Accept-Encoding and Accept-Language.
May a shared cache store it
Yes, where the origin sends public: section 5.2.2.9 says the directive indicates that a cache MAY store the response, subject to the constraints in section 3.
Cache status on a second request
A hit. In RFC 9211's header, a member with the hit parameter. On Cloudflare, CF-Cache-Status: HIT. In the lab, x-lab-cache: HIT. That the second request should be a hit is this page's advice: if it is not, the cache is not doing its job for this file.
An anonymous request for the same URL must return
The same file.
Your routes: ____________
Observed Cache-Control: ____________ Observed Vary: ____________
Cache status, first request: ____________ second request: ____________
Anonymous request returned: ____________ Checked on (date): ____________
ROW 2: A PUBLIC PAGE
HTML that is the same for every visitor, signed in or not.
Who may see it
Anyone.
Cache-Control the origin should send
Your choice, stated in the header: public with a short max-age or s-maxage if the shared cache should keep the page, or no-store if it should not. Not leaving it unsaid is this page's advice. RFC 9110 section 15.1 lists 200 among the status codes that are heuristically cacheable in that specification, unless the method definition or explicit cache controls indicate otherwise. In section 3, a status code defined as heuristically cacheable is one of the things that satisfies the last condition on the list. On this page's reading, a 200 response with no Cache-Control header can therefore still be one a cache is allowed to store. Each product then applies a default of its own, which is this page's observation from the Cloudflare, CloudFront and nginx documentation it cites.
Vary
Each request header the page depends on, as this page's advice. The RFC 9110 rule is the one in row 1: an origin server SHOULD generate Vary on a cacheable response when it wishes that response to be selectively reused. If the page shows anything about the signed-in person, such as a name in its header, it is not this row: use row 3.
May a shared cache store it
Yes, when it is the same for every visitor and the header allows it. This page's advice.
Cache status on a second request
A hit, where the cache is set to store pages. That expectation is this page's advice. On Cloudflare, DYNAMIC unless a rule makes the page eligible: its documentation says the Cloudflare CDN does not cache HTML or JSON by default.
An anonymous request for the same URL must return
The same page.
Your routes: ____________
Observed Cache-Control: ____________ Observed Vary: ____________
Cache status, first request: ____________ second request: ____________
Anonymous request returned: ____________ Checked on (date): ____________
ROW 3: A PAGE THAT DIFFERS BY SIGNED-IN PERSON
An account page, a dashboard, an order history, or a public page with a personal element in it.
Who may see it
The signed-in person, and nobody else.
Cache-Control the origin should send
private, no-store. Section 5.2.2.7: the unqualified private directive indicates that a shared cache MUST NOT store the response. Section 5.2.2.5: no-store indicates that a cache MUST NOT store any part of either the immediate request or the response. ASVS 5.0 requirement 14.3.2 (Level 2): sufficient anti-caching HTTP response header fields, which it gives as Cache-Control: no-store, so that sensitive data is not cached in browsers. Sending both directives is this page's advice, and the advice of the 2024 PortSwigger paper. Next.js documents a longer form for dynamically rendered pages: private, no-cache, no-store, max-age=0, must-revalidate.
Vary
Cookie, as this page's advice: a second signal for a cache that acts on Vary. It is not what keeps the response out of a shared cache. RFC 9110's SHOULD is for a cacheable response, which this is not, and RFC 9111 section 4.1 makes Vary a rule about reusing a stored response, not about storing one. Cloudflare's documentation says that by default it does not consider Vary values in caching decisions, outside the cases it lists.
May a shared cache store it
No. Section 3: a cache MUST NOT store a response unless, among its conditions, the no-store directive is not present and, for a shared cache, the private directive is either not present or allows a shared cache to store a modified response.
Cache status on a second request
Not a hit, on any request: a hit would mean a stored copy. That expectation is this page's advice. On Cloudflare, DYNAMIC where the route was not eligible for cache at all, or BYPASS where it was eligible and the origin's response was not cacheable. In the lab's careful pair, step 3 of the recorded run prints MISS for the second request to /account, the one sent with no cookie, which was answered with a 302 and no marker. For the first, signed-in request it prints the Cache-Control and Vary headers, private, no-store and Cookie, and not the cache status.
An anonymous request for the same URL must return
A redirect to sign-in, or a 401 or 403. Never the page. For an address that only resembles this route, such as the route with a file name added, a 404 or a 302: ASVS 5.0 requirement 14.2.5 (Level 3) says the web server should return a 404 or 302 response when a non-existent file is accessed rather than returning a different, valid file.
Your routes: ____________
Observed Cache-Control: ____________ Observed Vary: ____________
Cache status, first request: ____________ second request: ____________
Anonymous request returned: ____________ Checked on (date): ____________
ROW 4: AN API RESPONSE WITH PERSONAL DATA
JSON or other data returned for the signed-in caller.
Who may see it
The authenticated caller.
Cache-Control the origin should send
private, no-store, as in row 3. Where the caller is authenticated by an Authorization header, section 3 already says a shared cache MUST NOT store the response unless a response directive is present that explicitly allows shared caching, and section 3.5 names the three directives in the specification that do: must-revalidate, public and s-maxage. One of those three, sent without private or no-store, is what would open such a route to a shared cache. Where a cookie authenticates the caller, section 3 has no such condition, and the header is the instruction the cache has.
Vary
As in row 3. RFC 9110 section 12.5.5 says there is no need to send the Authorization field name in Vary.
May a shared cache store it
No, under the same section 3 conditions as row 3.
Cache status on a second request
Not a hit. On Cloudflare, DYNAMIC unless a rule makes the route eligible: its documentation says the Cloudflare CDN does not cache HTML or JSON by default.
An anonymous request for the same URL must return
A 401 or 403 with no data in it. This page's advice.
Your routes: ____________
Observed Cache-Control: ____________ Observed Vary: ____________
Cache status, first request: ____________ second request: ____________
Anonymous request returned: ____________ Checked on (date): ____________
ROW 5: A DOWNLOAD
A statement, invoice, export or report served as a file.
Who may see it
For a personal file, the person entitled to it. A public file that is the same for everyone belongs in row 1.
Cache-Control the origin should send
private, no-store. This is the row where the route's own address ends in a file extension, so a rule that reads only the URL takes it for a static file with no path confusion at all. Cloudflare's default cached file extensions include CSV, PDF, DOC, DOCX, XLS, XLSX and ZIP. Its documentation also says that Cache-Control: no-store or private from the origin prevents caching in either Origin Cache Control mode, and that a Cache Rule with an Edge Cache TTL setting that ignores origin cache-control overrides Cache-Control: no-store.
Vary
As in row 3.
May a shared cache store it
No, for a personal file, under the same section 3 conditions as row 3.
Cache status on a second request
Not a hit. On Cloudflare, BYPASS: the address is eligible by its extension and the origin's response is not cacheable.
An anonymous request for the same URL must return
A redirect to sign-in, or a 401 or 403. Never the file.
Your routes: ____________
Observed Cache-Control: ____________ Observed Vary: ____________
Cache status, first request: ____________ second request: ____________
Anonymous request returned: ____________ Checked on (date): ____________
ROW 6: AN ERROR PAGE
A 404, 403, 500 or similar response.
Who may see it
Anyone who causes the error. It carries nothing about a signed-in person: a name in the page header makes it row 3.
Cache-Control the origin should send
no-store, as this page's advice. Without an instruction, RFC 9110 section 15.1 lists 404, 405, 410, 414 and 501 among the heuristically cacheable status codes, and Cloudflare's documentation gives a default edge cache time of 3 minutes for 404 and 410 responses when no cache-control directive or expires header is present.
Vary
None needed.
May a shared cache store it
This page's advice: no. A short public lifetime on a plain 404 is a performance choice, and it is acceptable only when the page is identical for everyone.
Cache status on a second request
Not a hit.
An anonymous request for the same URL must return
The same error. For an address that only resembles a private route, an error or a redirect is the correct answer for everyone, signed in or not. The source behind it is ASVS 5.0 requirement 14.2.5 (Level 3): the web server should return a 404 or 302 response when a non-existent file is accessed rather than returning a different, valid file. Accepting any error or redirect, and giving the same answer signed in or not, are this page's additions.
Your routes: ____________
Observed Cache-Control: ____________ Observed Vary: ____________
Cache status, first request: ____________ second request: ____________
Anonymous request returned: ____________ Checked on (date): ____________
================================================================
PART 2: THE FOUR PATH-CONFUSION FIXTURES
================================================================
Each fixture is an address that a careless origin reads as a private page and a careless cache reads as a static file. In the lab the private page is /account. To build the same four for your own application, take one private path of your own, written here as PRIVATE, and a file name nobody else would request, written here as NAME.css. Change NAME on every attempt.
Fixture 1: a file name appended to a private path
Lab address /account/photo.css
Your address PRIVATE/NAME.css
A careless origin treats the extra segment as part of the page's own path and answers the page.
A careless cache sees a path that ends in .css.
Described by Omer Gil, 27 February 2017. The 2020 USENIX paper calls it the Path Parameter technique.
Fixture 2: a path parameter delimiter
Lab address /account;photo.css
Your address PRIVATE;NAME.css
A careless origin drops everything from the semicolon to the end of the segment.
A careless cache does not treat the semicolon as special, and sees a path that ends in .css.
Described by RFC 3986 section 3.3 notes that the semicolon is often used to delimit parameters applicable to a segment. The 2024 PortSwigger paper lists the semicolon in Spring first among its four origin delimiters.
Fixture 3: an encoded delimiter
Lab address /account%3Fphoto.css
Your address PRIVATE%3FNAME.css
A careless origin decodes %3F into a question mark before it splits the path from the query, so everything after it becomes a query string.
A careless cache does not decode, and sees a path that ends in .css.
Described by The 2020 USENIX paper, as its Encoded Question Mark technique, one of the five it tested.
Fixture 4: a normalised dot-segment
Lab address /static/..%2Faccount
Your address STATIC/..%2FPRIVATE, where STATIC is a folder one level deep that your cache has a rule for, and PRIVATE is written without its leading slash
A careless origin decodes %2F into a slash, resolves the dot-segment, and reads the result as the private path.
A careless cache does neither, and sees a path that starts with its static folder.
Described by The 2024 PortSwigger paper, for caches with a rule on a path prefix.
What a correct result looks like, for every fixture
Signed in as your test account: a 404 or a redirect, with nothing from the account page in the body. The source behind it is ASVS 5.0 requirement 14.2.5 (Level 3): the web server should return a 404 or 302 response when a non-existent file is accessed rather than returning a different, valid file. Accepting any redirect, and checking that nothing from the account page is in the body, are this page's additions.
With no session: the same 404 or redirect, and nothing from the test account.
Cache status on the second request: whatever your cache reports for an error page. The body is what matters.
Before you send any of them
Use an application you own or are authorised in writing to test, a test account that holds invented data, and staging where it sits behind the same cache configuration. If a fixture does return your test account's page to the request with no session, a copy of that page is now in the shared cache at that address: purge the address, then request it once more to confirm it has gone. Send both requests yourself. These four are examples, not every way two layers can disagree.
================================================================
PART 3: THE LAB FILES
================================================================
Make an empty folder named cache-deception-lab, save the eight files below into it under the names shown, and run the commands in Part 4 from that folder.
What each version does
careless origin Decodes the whole request target (if decoding throws an error, it uses the target as it arrived), drops the query, the fragment and any ;parameters, resolves dot-segments, then answers a defined path for itself and for anything underneath it. Sends no Cache-Control header on any response.
careful origin Takes the raw path, decodes nothing, and answers only when it equals a defined path. Sends public with a max-age on the stylesheet and the home page, private, no-store with Vary: Cookie on the three personal routes and on the redirect to sign-in, and no-store on the sign-in form, the sign-in result and every error page.
careless cache Stores any GET response whose path ends in .css, .csv, .js or .svg, or starts with /static/. Does not read the response.
careful cache Stores a GET response only when all of these hold: the status is 200, Cache-Control has neither private nor no-store, when the path ends in one of the lab's four static file extensions the content type is the one the lab lists for that extension, the response has no Vary header, and Cache-Control says public. A path with no such ending gets no content-type check.
both caches Key each entry on the method and the raw request target, forward the request to the origin with its cookie, and report what they did in an x-lab-cache response header. Neither has a clock or removes an entry, so a stored entry stays for as long as the cache that stored it runs. The run scripts and the test start a fresh cache for each pairing.
both origins Ask for the same sign-in before answering a personal route, and redirect a request with no valid session cookie to /sign-in.
The paths the origin defines
/ the home page, the same for every visitor
/sign-in the sign-in form (GET) and the sign-in itself (POST)
/static/site.css the stylesheet
/account the account page, with the private marker
/api/profile the profile API, with the private marker
/download/statement.csv the statement download, with the private marker
================================================================
FILE 1 OF 8: lab-common.mjs
================================================================
// lab-common.mjs: names and helpers for the lab. Every other lab file except
// run-fixtures.mjs and run-matrix.mjs imports from this one.
// Illustration only. The account, its password and the marker are invented.
export const NEWLINE = String.fromCharCode(10)
export const LOOPBACK = '127.0.0.1'
export const VERSIONS = ['careless', 'careful']
// The one account in the lab. Made up for this page; it is no product's default.
export const LAB_ACCOUNT = { username: 'lab-member', password: 'invented-lab-password-not-real' }
// The text the origin puts in the test account's three personal responses.
// lab.mjs looks for it in the body of each answer it summarises.
export const PRIVATE_MARKER = 'LAB-PRIVATE-MARKER for lab-member'
// The file extensions the lab treats as static, each with the content type
// the careful cache expects a response for that extension to have.
export const STATIC_TYPES = {
'.css': 'text/css',
'.csv': 'text/csv',
'.js': 'text/javascript',
'.svg': 'image/svg+xml',
}
export const STATIC_FOLDER = '/static/'
// Returns the text before the first occurrence of a delimiter, or all of it.
export function cutAtFirst(text, delimiter) {
const position = text.indexOf(delimiter)
return position === -1 ? text : text.slice(0, position)
}
// Returns the path of a request target: everything before the first question
// mark. Nothing is decoded.
export function readRawPath(target) {
return cutAtFirst(target, '?')
}
// Returns the static extension a path ends in, or an empty string.
export function readStaticExtension(path) {
for (const extension of Object.keys(STATIC_TYPES)) {
if (path.endsWith(extension)) return extension
}
return ''
}
// Stops on anything but one of the two version names.
export function requireVersion(name) {
if (VERSIONS.includes(name)) return name
throw new Error('Unknown version "' + name + '". Use careless or careful.')
}
export function readBody(stream) {
return new Promise((resolve, reject) => {
let body = ''
stream.setEncoding('utf8')
stream.on('data', (chunk) => { body += chunk })
stream.on('end', () => resolve(body))
stream.on('error', reject)
})
}
// Starts a server on 127.0.0.1 at a port the system picks, and returns the port.
export function listen(server) {
return new Promise((resolve) => {
server.listen(0, LOOPBACK, () => resolve(server.address().port))
})
}
export function stop(server) {
server.closeAllConnections()
return new Promise((resolve) => server.close(resolve))
}
================================================================
FILE 2 OF 8: origin.mjs
================================================================
// origin.mjs: the invented origin, Lab Ledger, in two versions.
// Illustration only. It is not how any real framework routes requests.
// careless answers a known page for paths that only resemble it, and
// sends no Cache-Control header on anything
// careful answers only the exact paths in ROUTES, and says on every
// response whether a shared cache may store it
// Both versions ask for the same sign-in before a personal route.
import http from 'node:http'
import { randomBytes } from 'node:crypto'
import { LAB_ACCOUNT, NEWLINE, PRIVATE_MARKER, cutAtFirst, listen, readBody, readRawPath, requireVersion } from './lab-common.mjs'
const SESSION_COOKIE = 'lab_session'
const HOME_PAGE = '<h1>Lab Ledger</h1><p>The same page for every visitor.</p>'
const SIGN_IN_FORM =
'<h1>Sign in to Lab Ledger</h1><form method="post" action="/sign-in">' +
'<input name="username" placeholder="username"> <input name="password" type="password" placeholder="password"> ' +
'<button>Sign in</button></form>'
const ACCOUNT_PAGE = '<h1>Your account</h1><p>' + PRIVATE_MARKER + '</p>'
const PROFILE_JSON = JSON.stringify({ username: LAB_ACCOUNT.username, note: PRIVATE_MARKER })
const STATEMENT_CSV = 'date,entry' + NEWLINE + '1901-01-01,' + PRIVATE_MARKER + NEWLINE
// Every path the origin defines. kind picks the caching headers below, and
// a personal route is answered only for a signed-in request.
const ROUTES = [
{ path: '/', label: 'the home page', kind: 'publicPage', type: 'text/html', body: HOME_PAGE },
{ path: '/sign-in', label: 'the sign-in form', kind: 'neverStored', type: 'text/html', body: SIGN_IN_FORM },
{ path: '/static/site.css', label: 'the stylesheet', kind: 'publicFile', type: 'text/css', body: 'body { font-family: sans-serif; }' },
{ path: '/account', label: 'the account page', kind: 'personal', type: 'text/html', body: ACCOUNT_PAGE },
{ path: '/api/profile', label: 'the profile API', kind: 'personal', type: 'application/json', body: PROFILE_JSON },
{ path: '/download/statement.csv', label: 'the statement download', kind: 'personal', type: 'text/csv', body: STATEMENT_CSV },
]
// What each version tells caches. The careless version tells them nothing.
const CACHING_HEADERS = {
careless: { publicFile: {}, publicPage: {}, personal: {}, neverStored: {} },
careful: {
publicFile: { 'cache-control': 'public, max-age=3600' },
publicPage: { 'cache-control': 'public, max-age=60' },
personal: { 'cache-control': 'private, no-store', vary: 'Cookie' },
neverStored: { 'cache-control': 'no-store' },
},
}
// CARELESS: decodes every percent-encoded character in the target, so an
// encoded question mark, hash or slash turns into a real one. If
// decodeURIComponent throws an error, the target is used as it arrived, with
// nothing decoded.
function decodeTarget(target) {
try {
return decodeURIComponent(target)
} catch (error) {
return target
}
}
// CARELESS: resolves "." and ".." segments.
function removeDotSegments(segments) {
const kept = []
for (const segment of segments) {
if (segment === '.') continue
if (segment === '..') {
if (kept.length > 1) kept.pop()
continue
}
kept.push(segment)
}
return kept
}
// CARELESS: decode first, then drop the query and the fragment, drop
// ";parameters" from each segment, and resolve dot-segments.
function readPathCarelessly(target) {
const decoded = decodeTarget(target)
const withoutQuery = cutAtFirst(cutAtFirst(decoded, '?'), '#')
const segments = withoutQuery.split('/').map((segment) => cutAtFirst(segment, ';'))
return removeDotSegments(segments).join('/') || '/'
}
// CARELESS: a defined path also answers for anything underneath it.
function findRouteCarelessly(target) {
const path = readPathCarelessly(target)
return ROUTES.find((route) => path === route.path || path.startsWith(route.path + '/'))
}
// CAREFUL: the raw path, with nothing decoded, must equal a defined path.
function findRouteCarefully(target) {
const path = readRawPath(target)
return ROUTES.find((route) => path === route.path)
}
function findRoute(version, target) {
return version === 'careless' ? findRouteCarelessly(target) : findRouteCarefully(target)
}
// Says in words how one version reads a target. run-fixtures.mjs prints it.
export function describeOriginReading(version, target) {
const route = findRoute(version, target)
return route ? route.path + ', ' + route.label : 'no route, so 404'
}
function isSignedIn(sessions, request) {
const cookies = String(request.headers.cookie || '').split(';')
for (const cookie of cookies) {
const pair = cookie.trim().split('=')
if (pair[0] === SESSION_COOKIE && sessions.has(pair[1])) return true
}
return false
}
function send(response, status, headers, body) {
response.writeHead(status, headers)
response.end(body)
}
function sendRoute(version, response, route) {
const headers = Object.assign({ 'content-type': route.type }, CACHING_HEADERS[version][route.kind])
send(response, 200, headers, route.body)
}
function sendError(version, response, status, message) {
const headers = Object.assign({ 'content-type': 'text/html' }, CACHING_HEADERS[version].neverStored)
send(response, status, headers, '<h1>' + status + '</h1><p>' + message + '</p>')
}
function sendSignInRedirect(version, response) {
const headers = Object.assign({ location: '/sign-in' }, CACHING_HEADERS[version].personal)
send(response, 302, headers, '')
}
// Checks the one lab account with a plain comparison, which is enough for an
// invented password. On success it starts a session and sets the cookie,
// without the Secure attribute because the lab speaks plain HTTP on 127.0.0.1.
async function handleSignIn(version, sessions, request, response) {
const form = new URLSearchParams(await readBody(request))
const isLabAccount = form.get('username') === LAB_ACCOUNT.username && form.get('password') === LAB_ACCOUNT.password
if (!isLabAccount) return sendError(version, response, 401, 'Wrong username or password')
const token = randomBytes(16).toString('hex')
sessions.add(token)
const cookie = SESSION_COOKIE + '=' + token + '; Path=/; HttpOnly; SameSite=Lax'
const headers = Object.assign({ location: '/account', 'set-cookie': cookie }, CACHING_HEADERS[version].neverStored)
send(response, 303, headers, '')
}
function handleRequest(version, sessions, request, response) {
if (request.method === 'POST' && readRawPath(request.url) === '/sign-in') {
return handleSignIn(version, sessions, request, response).catch(() => sendError(version, response, 400, 'Bad request'))
}
if (request.method !== 'GET') return sendError(version, response, 405, 'Method not allowed')
const route = findRoute(version, request.url)
if (!route) return sendError(version, response, 404, 'Not found')
if (route.kind === 'personal' && !isSignedIn(sessions, request)) return sendSignInRedirect(version, response)
sendRoute(version, response, route)
}
// Starts one version of the origin. Sessions live in memory until it stops.
export async function startOrigin(versionName) {
const version = requireVersion(versionName)
const sessions = new Set()
const server = http.createServer((request, response) => handleRequest(version, sessions, request, response))
const port = await listen(server)
return { server, port }
}
================================================================
FILE 3 OF 8: cache.mjs
================================================================
// cache.mjs: a small shared cache written for this lab. It sits in front of
// the lab origin and keeps what it stores in memory, in two versions.
// careless decides from the URL alone: it stores any GET response whose
// path ends in one of the lab's static file extensions or
// starts with /static/
// careful decides from the origin's response: it stores a 200 response
// only when Cache-Control says public, never when it says
// private or no-store, never when the response has a Vary
// header, and, when the path ends in one of the lab's four
// static file extensions, only when the content type is the
// one the lab lists for that extension. A path with no such
// ending gets no content-type check.
// Illustration only. It has no clock and never removes a stored entry: an
// entry stays for as long as the cache that stored it runs, and each
// startCache call begins with no entries. It does no validation and no Vary
// matching. It shows the pattern, not how any real CDN or proxy decides what
// to store.
import http from 'node:http'
import { LOOPBACK, STATIC_FOLDER, STATIC_TYPES, cutAtFirst, listen, readBody, readRawPath, readStaticExtension, requireVersion } from './lab-common.mjs'
const STATUS_HEADER = 'x-lab-cache'
function stored(reason) {
return { shouldStore: true, text: 'stored (' + reason + ')' }
}
function notStored(reason) {
return { shouldStore: false, text: 'not stored (' + reason + ')' }
}
// Says what makes a target look static to a rule that reads only the URL,
// or returns an empty string. The fixture script prints it too.
export function describeStaticLook(target) {
const path = readRawPath(target)
const extension = readStaticExtension(path)
if (extension) return 'ends in ' + extension
if (path.startsWith(STATIC_FOLDER)) return 'starts with ' + STATIC_FOLDER
return ''
}
// CARELESS: the URL alone decides. The response is not read at all.
function decideCarelessly(request) {
const look = describeStaticLook(request.url)
return look ? stored('the URL ' + look) : notStored('the URL does not look static')
}
// Returns the directive names in a Cache-Control value, without arguments.
function readDirectiveNames(headerValue) {
const names = new Set()
for (const part of String(headerValue || '').split(',')) {
const name = cutAtFirst(part.trim().toLowerCase(), '=')
if (name) names.add(name)
}
return names
}
// Returns a sentence when the path ends in a static extension and the
// response's content type is not the one listed for it, else an empty string.
function describeTypeMismatch(request, reply) {
const extension = readStaticExtension(readRawPath(request.url))
if (!extension) return ''
const contentType = cutAtFirst(String(reply.headers['content-type'] || ''), ';').trim()
if (contentType === STATIC_TYPES[extension]) return ''
return 'content type ' + (contentType || 'missing') + ' does not match ' + extension
}
// CAREFUL: the origin's response decides, in this order.
function decideCarefully(request, reply) {
const directives = readDirectiveNames(reply.headers['cache-control'])
if (reply.status !== 200) return notStored('status ' + reply.status)
if (directives.has('no-store') || directives.has('private')) return notStored('the origin said private or no-store')
const mismatch = describeTypeMismatch(request, reply)
if (mismatch) return notStored(mismatch)
if (reply.headers.vary) return notStored('the response has Vary, which this cache does not match on')
if (!directives.has('public')) return notStored('the origin did not say public')
return stored('the origin said public')
}
function decideStorage(version, request, reply) {
if (request.method !== 'GET') return notStored('only GET responses are stored')
return version === 'careless' ? decideCarelessly(request) : decideCarefully(request, reply)
}
// Sends the request on to the origin: the same method, raw target and body,
// and the same headers apart from Connection, so the cookie goes too.
function forwardToOrigin(originPort, request, body) {
return new Promise((resolve, reject) => {
const headers = Object.assign({}, request.headers)
delete headers.connection
const options = { host: LOOPBACK, port: originPort, method: request.method, path: request.url, headers, agent: false }
const outgoing = http.request(options, (incoming) => {
readBody(incoming).then((replyBody) => resolve({ status: incoming.statusCode, headers: incoming.headers, body: replyBody }), reject)
})
outgoing.on('error', reject)
outgoing.end(body)
})
}
function sendReply(response, reply, cacheStatus) {
const headers = Object.assign({}, reply.headers)
headers[STATUS_HEADER] = cacheStatus
delete headers.connection
delete headers['transfer-encoding']
delete headers['content-length']
response.writeHead(reply.status, headers)
response.end(reply.body)
}
// The key is the method and the raw target. Cookies are not part of it, so
// a stored entry is served to whoever asks for the same target next.
async function handleRequest(cache, request, response) {
const key = request.method + ' ' + request.url
const entry = cache.entries.get(key)
if (entry) return sendReply(response, entry, 'HIT')
const reply = await forwardToOrigin(cache.originPort, request, await readBody(request))
const decision = decideStorage(cache.version, request, reply)
if (decision.shouldStore) cache.entries.set(key, reply)
sendReply(response, reply, 'MISS, ' + decision.text)
}
function sendGatewayError(response) {
response.writeHead(502, { 'content-type': 'text/plain' })
response.end('The lab cache could not reach the lab origin.')
}
// Starts one version of the cache in front of the origin on originPort.
export async function startCache(versionName, originPort) {
const cache = { version: requireVersion(versionName), originPort, entries: new Map() }
const server = http.createServer((request, response) => {
handleRequest(cache, request, response).catch(() => sendGatewayError(response))
})
const port = await listen(server)
return { server, port }
}
================================================================
FILE 4 OF 8: lab.mjs
================================================================
// lab.mjs: starts an origin with a cache in front of it, and holds the
// requests the run scripts and the regression test send.
import http from 'node:http'
import { LAB_ACCOUNT, LOOPBACK, PRIVATE_MARKER, readBody, stop } from './lab-common.mjs'
import { startOrigin } from './origin.mjs'
import { startCache } from './cache.mjs'
// Every pairing of an origin version with a cache version.
export const COMBINATIONS = [
{ origin: 'careless', cache: 'careless' },
{ origin: 'careless', cache: 'careful' },
{ origin: 'careful', cache: 'careless' },
{ origin: 'careful', cache: 'careful' },
]
// The four path-confusion fixtures. None of these paths is defined by the
// origin: each one only resembles /account to the careless version.
export const FIXTURES = [
{ name: 'a file name appended to a private path', path: '/account/photo.css' },
{ name: 'a path parameter delimiter', path: '/account;photo.css' },
{ name: 'an encoded delimiter', path: '/account%3Fphoto.css' },
{ name: 'a normalised dot-segment', path: '/static/..%2Faccount' },
]
// One path for each row of the response-cache matrix.
export const ROUTE_TYPES = [
{ name: 'public static file', path: '/static/site.css' },
{ name: 'public page', path: '/' },
{ name: 'page that differs by person', path: '/account' },
{ name: 'API response, personal data', path: '/api/profile' },
{ name: 'download, personal data', path: '/download/statement.csv' },
{ name: 'error page', path: '/no-such-page' },
]
// Starts one combination. Requests go to cachePort; the origin's port is
// known only to the cache.
export async function startLab(combination) {
const origin = await startOrigin(combination.origin)
const cache = await startCache(combination.cache, origin.port)
const close = () => Promise.all([stop(cache.server), stop(origin.server)])
return { cachePort: cache.port, close }
}
// Sends one request to the cache with node:http and resolves with the
// status, headers and body that came back.
export function sendRequest(port, request) {
return new Promise((resolve, reject) => {
const headers = Object.assign({}, request.headers)
const options = { host: LOOPBACK, port, method: request.method || 'GET', path: request.path, headers, agent: false }
const outgoing = http.request(options, (incoming) => {
readBody(incoming).then((body) => resolve({ status: incoming.statusCode, headers: incoming.headers, body }), reject)
})
outgoing.on('error', reject)
outgoing.end(request.body || '')
})
}
// Signs in as the invented account and returns the session cookie pair.
export async function signIn(port) {
const body = new URLSearchParams(LAB_ACCOUNT).toString()
const headers = { 'content-type': 'application/x-www-form-urlencoded' }
const reply = await sendRequest(port, { method: 'POST', path: '/sign-in', headers, body })
const cookies = reply.headers['set-cookie'] || []
if (cookies.length === 0) throw new Error('Sign-in failed with status ' + reply.status)
return cookies[0].split(';')[0]
}
// Keeps the parts of an answer the scripts print or test.
function summarise(reply) {
return {
status: reply.status,
location: reply.headers.location || '',
contentType: reply.headers['content-type'] || '(not sent)',
cacheControl: reply.headers['cache-control'] || '(not sent)',
vary: reply.headers.vary || '(not sent)',
cacheStatus: reply.headers['x-lab-cache'],
hasMarker: reply.body.includes(PRIVATE_MARKER),
}
}
// The two requests behind every result: the path with the test account's
// cookie, then the same path with no cookie at all.
export async function visitTwice(port, cookie, path) {
const signedIn = await sendRequest(port, { path, headers: { cookie } })
const anonymous = await sendRequest(port, { path })
return { path, signedIn: summarise(signedIn), anonymous: summarise(anonymous) }
}
// Starts a combination, signs in once and visits every listed path twice.
export async function observe(combination, cases) {
const lab = await startLab(combination)
try {
const cookie = await signIn(lab.cachePort)
const visits = []
for (const item of cases) visits.push(await visitTwice(lab.cachePort, cookie, item.path))
return visits
} finally {
await lab.close()
}
}
================================================================
FILE 5 OF 8: run-fixtures.mjs
================================================================
// run-fixtures.mjs: sends the four path-confusion fixtures through every
// pairing of origin and cache. For each fixture it requests the path signed
// in as the test account, then requests the same path with no cookie, and
// prints both answers and whether each one held the private marker.
import { describeOriginReading } from './origin.mjs'
import { describeStaticLook } from './cache.mjs'
import { COMBINATIONS, FIXTURES, observe } from './lab.mjs'
const LINE = '================================================================'
const INDENT = ' '
function describeStatus(answer) {
return answer.location ? answer.status + ' to ' + answer.location : String(answer.status)
}
function printAnswer(label, answer) {
const headers = 'Content-Type: ' + answer.contentType + ' Cache-Control: ' + answer.cacheControl + ' Vary: ' + answer.vary
console.log(' ' + label + describeStatus(answer) + ' ' + headers)
console.log(INDENT + 'lab cache: ' + answer.cacheStatus)
}
function printFixture(combination, fixture, number, visit) {
console.log('')
console.log('FIXTURE ' + number + ': ' + fixture.name)
console.log(' GET ' + fixture.path)
console.log(' the ' + combination.origin + ' origin reads it as: ' + describeOriginReading(combination.origin, fixture.path))
console.log(' a rule that looks only at the URL sees: a path that ' + (describeStaticLook(fixture.path) || 'does not look static'))
printAnswer('signed in ', visit.signedIn)
printAnswer('no cookie ', visit.anonymous)
console.log(' private marker in the signed-in response: ' + (visit.signedIn.hasMarker ? 'YES' : 'no'))
console.log(' private marker in the anonymous response: ' + (visit.anonymous.hasMarker ? 'YES' : 'no'))
}
async function runCombination(combination) {
const visits = await observe(combination, FIXTURES)
console.log(LINE)
console.log('ORIGIN: ' + combination.origin + ' CACHE: ' + combination.cache)
console.log(LINE)
FIXTURES.forEach((fixture, index) => printFixture(combination, fixture, index + 1, visits[index]))
const leaked = visits.filter((visit) => visit.anonymous.hasMarker).length
console.log('')
console.log('RESULT: the anonymous request received the private marker in ' + leaked + ' of ' + visits.length + ' fixtures')
console.log('')
}
for (const combination of COMBINATIONS) await runCombination(combination)
================================================================
FILE 6 OF 8: run-matrix.mjs
================================================================
// run-matrix.mjs: fills in the response-cache matrix for the lab's own six
// route types, under every pairing of origin and cache. Each path is
// requested signed in as the test account, then again with no cookie.
// Cache-Control and Vary are read from the first answer. The last two
// columns describe the second.
import { COMBINATIONS, ROUTE_TYPES, observe } from './lab.mjs'
const LINE = '================================================================'
const WIDTHS = [29, 25, 23, 12, 16]
const HEADINGS = ['route type', 'path', 'Cache-Control', 'Vary', 'second request']
function formatRow(cells, lastCell) {
const padded = cells.map((cell, index) => String(cell).padEnd(WIDTHS[index]))
return padded.join('') + lastCell
}
function describeAnonymousAnswer(answer) {
return answer.status + ', ' + (answer.hasMarker ? 'PRIVATE MARKER' : 'no marker')
}
// The first word of the lab cache's status on the second request, the one
// with no cookie: HIT or MISS.
function readHitOrMiss(answer) {
return answer.cacheStatus.split(',')[0]
}
function printRow(routeType, visit) {
const cells = [routeType.name, routeType.path, visit.signedIn.cacheControl, visit.signedIn.vary, readHitOrMiss(visit.anonymous)]
console.log(formatRow(cells, describeAnonymousAnswer(visit.anonymous)))
}
async function runCombination(combination) {
const visits = await observe(combination, ROUTE_TYPES)
console.log(LINE)
console.log('ORIGIN: ' + combination.origin + ' CACHE: ' + combination.cache)
console.log(LINE)
console.log(formatRow(HEADINGS, 'anonymous request gets'))
ROUTE_TYPES.forEach((routeType, index) => printRow(routeType, visits[index]))
console.log('')
}
for (const combination of COMBINATIONS) await runCombination(combination)
================================================================
FILE 7 OF 8: deception.test.mjs
================================================================
// deception.test.mjs: the regression test for one pairing of origin and cache.
// Usage: node deception.test.mjs careless careless
// node deception.test.mjs careful careful
// The first word names the origin version and the second the cache version.
// With no words it tests the careful origin behind the careful cache.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { requireVersion } from './lab-common.mjs'
import { FIXTURES, ROUTE_TYPES, observe } from './lab.mjs'
const combination = {
origin: requireVersion(process.argv[2] || 'careful'),
cache: requireVersion(process.argv[3] || 'careful'),
}
const label = combination.origin + ' origin, ' + combination.cache + ' cache: '
const fixtureVisits = await observe(combination, FIXTURES)
const routeVisits = await observe(combination, ROUTE_TYPES)
// The personal routes are the ones whose signed-in answer holds the marker.
const personalVisits = routeVisits.filter((visit) => visit.signedIn.hasMarker)
const stylesheetVisit = routeVisits.find((visit) => visit.path === '/static/site.css')
// The outcome that matters, one test for each fixture and personal route.
function testNoMarkerForAnonymous(name, visit) {
test(label + 'no private marker for an anonymous request to ' + name, () => {
assert.equal(visit.anonymous.hasMarker, false, 'the anonymous request for ' + visit.path + ' received the private marker')
})
}
FIXTURES.forEach((fixture, index) => testNoMarkerForAnonymous('fixture ' + (index + 1) + ' (' + fixture.name + ')', fixtureVisits[index]))
for (const visit of personalVisits) testNoMarkerForAnonymous(visit.path, visit)
// The origin's part: refuse what it does not define.
test(label + 'the origin answers 404 to every fixture path, signed in', () => {
const answered = fixtureVisits.filter((visit) => visit.signedIn.status !== 404)
const paths = answered.map((visit) => visit.path + ' (' + visit.signedIn.status + ')')
assert.equal(paths.length, 0, 'answered without a 404: ' + paths.join(', '))
})
// The origin's part: mark what is personal.
test(label + 'every response with the private marker says private, no-store', () => {
const marked = fixtureVisits.concat(routeVisits).filter((visit) => visit.signedIn.hasMarker)
const unmarked = marked.filter((visit) => visit.signedIn.cacheControl !== 'private, no-store')
const paths = unmarked.map((visit) => visit.path)
assert.equal(paths.length, 0, 'sent without private, no-store: ' + paths.join(', '))
})
// The cache still has to do its job for what is public.
test(label + 'the public stylesheet is served from the cache on the second request', () => {
assert.equal(stylesheetVisit.anonymous.cacheStatus, 'HIT', stylesheetVisit.path + ' came back as ' + stylesheetVisit.anonymous.cacheStatus)
})
================================================================
FILE 8 OF 8: serve.mjs
================================================================
// serve.mjs: starts one pairing of origin and cache and keeps it running, so
// you can look at the same responses in your own browser's network panel.
// Usage: node serve.mjs careless careless, or node serve.mjs careful careful
import { LAB_ACCOUNT, requireVersion } from './lab-common.mjs'
import { FIXTURES, startLab } from './lab.mjs'
const combination = {
origin: requireVersion(process.argv[2] || 'careful'),
cache: requireVersion(process.argv[3] || 'careful'),
}
const lab = await startLab(combination)
const address = 'http://127.0.0.1:' + lab.cachePort
console.log(combination.origin + ' origin behind ' + combination.cache + ' cache, listening on ' + address + ', process id ' + process.pid)
console.log('sign in at ' + address + '/sign-in as ' + LAB_ACCOUNT.username + ' with the password ' + LAB_ACCOUNT.password)
console.log('then open ' + address + FIXTURES[0].path + ' signed in, and again in a private window')
console.log('stop it with Ctrl+C, or by its process id')
================================================================
PART 4: THE RECORDED RUN
================================================================
Each command was run from the cache-deception-lab folder, in this order, in a folder that held only the eight files. Every output is copied from that run by a script. Lines were cut from three outputs, steps 4, 5 and 6: in the detail of each failed check, everything after the failure message, which is the two values compared, the stack trace and the error's properties. The stack trace names files on the computer that ran the lab. Each cut is marked where it was made, with the number of lines.
Step 1. Command: node --version
v26.0.0
Exit code: 0
Reading it: the version of Node.js every step below was run on.
Step 2. Command: node run-fixtures.mjs
================================================================
ORIGIN: careless CACHE: careless
================================================================
FIXTURE 1: a file name appended to a private path
GET /account/photo.css
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that ends in .css
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, stored (the URL ends in .css)
no cookie 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: YES
private marker in the anonymous response: YES
FIXTURE 2: a path parameter delimiter
GET /account;photo.css
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that ends in .css
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, stored (the URL ends in .css)
no cookie 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: YES
private marker in the anonymous response: YES
FIXTURE 3: an encoded delimiter
GET /account%3Fphoto.css
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that ends in .css
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, stored (the URL ends in .css)
no cookie 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: YES
private marker in the anonymous response: YES
FIXTURE 4: a normalised dot-segment
GET /static/..%2Faccount
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that starts with /static/
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, stored (the URL starts with /static/)
no cookie 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: YES
private marker in the anonymous response: YES
RESULT: the anonymous request received the private marker in 4 of 4 fixtures
================================================================
ORIGIN: careless CACHE: careful
================================================================
FIXTURE 1: a file name appended to a private path
GET /account/photo.css
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that ends in .css
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (content type text/html does not match .css)
no cookie 302 to /sign-in Content-Type: (not sent) Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (status 302)
private marker in the signed-in response: YES
private marker in the anonymous response: no
FIXTURE 2: a path parameter delimiter
GET /account;photo.css
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that ends in .css
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (content type text/html does not match .css)
no cookie 302 to /sign-in Content-Type: (not sent) Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (status 302)
private marker in the signed-in response: YES
private marker in the anonymous response: no
FIXTURE 3: an encoded delimiter
GET /account%3Fphoto.css
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that ends in .css
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (content type text/html does not match .css)
no cookie 302 to /sign-in Content-Type: (not sent) Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (status 302)
private marker in the signed-in response: YES
private marker in the anonymous response: no
FIXTURE 4: a normalised dot-segment
GET /static/..%2Faccount
the careless origin reads it as: /account, the account page
a rule that looks only at the URL sees: a path that starts with /static/
signed in 200 Content-Type: text/html Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (the origin did not say public)
no cookie 302 to /sign-in Content-Type: (not sent) Cache-Control: (not sent) Vary: (not sent)
lab cache: MISS, not stored (status 302)
private marker in the signed-in response: YES
private marker in the anonymous response: no
RESULT: the anonymous request received the private marker in 0 of 4 fixtures
================================================================
ORIGIN: careful CACHE: careless
================================================================
FIXTURE 1: a file name appended to a private path
GET /account/photo.css
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that ends in .css
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, stored (the URL ends in .css)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: no
private marker in the anonymous response: no
FIXTURE 2: a path parameter delimiter
GET /account;photo.css
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that ends in .css
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, stored (the URL ends in .css)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: no
private marker in the anonymous response: no
FIXTURE 3: an encoded delimiter
GET /account%3Fphoto.css
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that ends in .css
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, stored (the URL ends in .css)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: no
private marker in the anonymous response: no
FIXTURE 4: a normalised dot-segment
GET /static/..%2Faccount
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that starts with /static/
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, stored (the URL starts with /static/)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: HIT
private marker in the signed-in response: no
private marker in the anonymous response: no
RESULT: the anonymous request received the private marker in 0 of 4 fixtures
================================================================
ORIGIN: careful CACHE: careful
================================================================
FIXTURE 1: a file name appended to a private path
GET /account/photo.css
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that ends in .css
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
private marker in the signed-in response: no
private marker in the anonymous response: no
FIXTURE 2: a path parameter delimiter
GET /account;photo.css
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that ends in .css
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
private marker in the signed-in response: no
private marker in the anonymous response: no
FIXTURE 3: an encoded delimiter
GET /account%3Fphoto.css
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that ends in .css
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
private marker in the signed-in response: no
private marker in the anonymous response: no
FIXTURE 4: a normalised dot-segment
GET /static/..%2Faccount
the careful origin reads it as: no route, so 404
a rule that looks only at the URL sees: a path that starts with /static/
signed in 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
no cookie 404 Content-Type: text/html Cache-Control: no-store Vary: (not sent)
lab cache: MISS, not stored (status 404)
private marker in the signed-in response: no
private marker in the anonymous response: no
RESULT: the anonymous request received the private marker in 0 of 4 fixtures
Exit code: 0
Reading it: each block is one fixture under one pairing. The first two lines under the address say how that pairing's origin reads it and what a rule that looks only at the URL would see. Then come the two answers, signed in and with no cookie, each with the lab cache's own status.
Careless origin, careless cache: all four signed-in answers are the account page, status 200 with no Cache-Control header. The cache stores each one, three because the path ends in .css and one because it starts with /static/. Each request with no cookie is a HIT and carries the private marker: 4 of 4.
Careless origin, careful cache: the origin has not changed, and all four signed-in answers still carry the marker. The cache stores none of them, three because text/html does not match .css and one because the origin did not say public. Each request with no cookie goes to the origin and is redirected to /sign-in: 0 of 4.
Careful origin, careless cache: the origin has no route for any of the four and answers 404 with no-store. The careless cache does not read that header and stores the error pages, so each request with no cookie is a HIT on a 404 with nothing private in it: 0 of 4.
Careful origin, careful cache: 404 with no-store, nothing stored, 0 of 4.
Step 3. Command: node run-matrix.mjs
================================================================
ORIGIN: careless CACHE: careless
================================================================
route type path Cache-Control Vary second request anonymous request gets
public static file /static/site.css (not sent) (not sent) HIT 200, no marker
public page / (not sent) (not sent) MISS 200, no marker
page that differs by person /account (not sent) (not sent) MISS 302, no marker
API response, personal data /api/profile (not sent) (not sent) MISS 302, no marker
download, personal data /download/statement.csv (not sent) (not sent) HIT 200, PRIVATE MARKER
error page /no-such-page (not sent) (not sent) MISS 404, no marker
================================================================
ORIGIN: careless CACHE: careful
================================================================
route type path Cache-Control Vary second request anonymous request gets
public static file /static/site.css (not sent) (not sent) MISS 200, no marker
public page / (not sent) (not sent) MISS 200, no marker
page that differs by person /account (not sent) (not sent) MISS 302, no marker
API response, personal data /api/profile (not sent) (not sent) MISS 302, no marker
download, personal data /download/statement.csv (not sent) (not sent) MISS 302, no marker
error page /no-such-page (not sent) (not sent) MISS 404, no marker
================================================================
ORIGIN: careful CACHE: careless
================================================================
route type path Cache-Control Vary second request anonymous request gets
public static file /static/site.css public, max-age=3600 (not sent) HIT 200, no marker
public page / public, max-age=60 (not sent) MISS 200, no marker
page that differs by person /account private, no-store Cookie MISS 302, no marker
API response, personal data /api/profile private, no-store Cookie MISS 302, no marker
download, personal data /download/statement.csv private, no-store Cookie HIT 200, PRIVATE MARKER
error page /no-such-page no-store (not sent) MISS 404, no marker
================================================================
ORIGIN: careful CACHE: careful
================================================================
route type path Cache-Control Vary second request anonymous request gets
public static file /static/site.css public, max-age=3600 (not sent) HIT 200, no marker
public page / public, max-age=60 (not sent) HIT 200, no marker
page that differs by person /account private, no-store Cookie MISS 302, no marker
API response, personal data /api/profile private, no-store Cookie MISS 302, no marker
download, personal data /download/statement.csv private, no-store Cookie MISS 302, no marker
error page /no-such-page no-store (not sent) MISS 404, no marker
Exit code: 0
Reading it: one row for each route type in Part 1, under each pairing. Cache-Control and Vary are from the signed-in answer. The last two columns describe the second request, the one with no cookie.
The row to look at is the download. Its own address ends in .csv, so under the careless cache it is stored and the request with no cookie receives the test account's statement, a HIT with the private marker. That happens with the careless origin and again with the careful origin, which sent private, no-store: the careless cache does not read the header.
With the careless origin behind the careful cache nothing leaks, and nothing is cached either: the stylesheet is a MISS on its second request, because the origin never said it was public.
With the careful pair, the stylesheet and the home page are HITs on the second request, the three personal routes are not stored, and the request with no cookie is redirected to sign-in on each of them.
Step 4. Command: node deception.test.mjs careless careless
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 1 (a file name appended to a private path) (1.259625ms)
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 2 (a path parameter delimiter) (0.093875ms)
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 3 (an encoded delimiter) (0.076791ms)
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 4 (a normalised dot-segment) (0.06525ms)
✔ careless origin, careless cache: no private marker for an anonymous request to /account (0.068916ms)
✔ careless origin, careless cache: no private marker for an anonymous request to /api/profile (0.048917ms)
✖ careless origin, careless cache: no private marker for an anonymous request to /download/statement.csv (0.057375ms)
✖ careless origin, careless cache: the origin answers 404 to every fixture path, signed in (0.101083ms)
✖ careless origin, careless cache: every response with the private marker says private, no-store (0.084875ms)
✔ careless origin, careless cache: the public stylesheet is served from the cache on the second request (0.092084ms)
ℹ tests 10
ℹ suites 0
ℹ pass 3
ℹ fail 7
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 5.53575
✖ failing tests:
test at deception.test.mjs:25:3
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 1 (a file name appended to a private path) (1.259625ms)
AssertionError [ERR_ASSERTION]: the anonymous request for /account/photo.css received the private marker
(16 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:25:3
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 2 (a path parameter delimiter) (0.093875ms)
AssertionError [ERR_ASSERTION]: the anonymous request for /account;photo.css received the private marker
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:25:3
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 3 (an encoded delimiter) (0.076791ms)
AssertionError [ERR_ASSERTION]: the anonymous request for /account%3Fphoto.css received the private marker
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:25:3
✖ careless origin, careless cache: no private marker for an anonymous request to fixture 4 (a normalised dot-segment) (0.06525ms)
AssertionError [ERR_ASSERTION]: the anonymous request for /static/..%2Faccount received the private marker
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:25:3
✖ careless origin, careless cache: no private marker for an anonymous request to /download/statement.csv (0.057375ms)
AssertionError [ERR_ASSERTION]: the anonymous request for /download/statement.csv received the private marker
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:34:1
✖ careless origin, careless cache: the origin answers 404 to every fixture path, signed in (0.101083ms)
AssertionError [ERR_ASSERTION]: answered without a 404: /account/photo.css (200), /account;photo.css (200), /account%3Fphoto.css (200), /static/..%2Faccount (200)
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:41:1
✖ careless origin, careless cache: every response with the private marker says private, no-store (0.084875ms)
AssertionError [ERR_ASSERTION]: sent without private, no-store: /account/photo.css, /account;photo.css, /account%3Fphoto.css, /static/..%2Faccount, /account, /api/profile, /download/statement.csv
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
Exit code: 1
Reading it: the careless pair fails seven of the ten checks. Five are the outcome itself, the request with no cookie receiving the marker on the four fixtures and on the download. Two are the origin: it answered 200 to all four fixture paths, and it sent seven responses that carry the marker without private, no-store. The process exits with code 1.
Step 5. Command: node deception.test.mjs careless careful
✔ careless origin, careful cache: no private marker for an anonymous request to fixture 1 (a file name appended to a private path) (0.6905ms)
✔ careless origin, careful cache: no private marker for an anonymous request to fixture 2 (a path parameter delimiter) (0.047583ms)
✔ careless origin, careful cache: no private marker for an anonymous request to fixture 3 (an encoded delimiter) (0.042125ms)
✔ careless origin, careful cache: no private marker for an anonymous request to fixture 4 (a normalised dot-segment) (0.033375ms)
✔ careless origin, careful cache: no private marker for an anonymous request to /account (0.033959ms)
✔ careless origin, careful cache: no private marker for an anonymous request to /api/profile (0.027667ms)
✔ careless origin, careful cache: no private marker for an anonymous request to /download/statement.csv (0.02975ms)
✖ careless origin, careful cache: the origin answers 404 to every fixture path, signed in (0.672375ms)
✖ careless origin, careful cache: every response with the private marker says private, no-store (0.105417ms)
✖ careless origin, careful cache: the public stylesheet is served from the cache on the second request (0.229041ms)
ℹ tests 10
ℹ suites 0
ℹ pass 7
ℹ fail 3
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4.924333
✖ failing tests:
test at deception.test.mjs:34:1
✖ careless origin, careful cache: the origin answers 404 to every fixture path, signed in (0.672375ms)
AssertionError [ERR_ASSERTION]: answered without a 404: /account/photo.css (200), /account;photo.css (200), /account%3Fphoto.css (200), /static/..%2Faccount (200)
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:41:1
✖ careless origin, careful cache: every response with the private marker says private, no-store (0.105417ms)
AssertionError [ERR_ASSERTION]: sent without private, no-store: /account/photo.css, /account;photo.css, /account%3Fphoto.css, /static/..%2Faccount, /account, /api/profile, /download/statement.csv
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
test at deception.test.mjs:49:1
✖ careless origin, careful cache: the public stylesheet is served from the cache on the second request (0.229041ms)
AssertionError [ERR_ASSERTION]: /static/site.css came back as MISS, not stored (the origin did not say public)
(20 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
Exit code: 1
Reading it: with only the cache made careful, the seven outcome checks pass and three checks still fail. Two are the same two origin checks as before, because the origin has not changed. The third is new: the public stylesheet is no longer served from the cache, because the origin never said it was public.
Step 6. Command: node deception.test.mjs careful careless
✔ careful origin, careless cache: no private marker for an anonymous request to fixture 1 (a file name appended to a private path) (0.695083ms)
✔ careful origin, careless cache: no private marker for an anonymous request to fixture 2 (a path parameter delimiter) (0.05825ms)
✔ careful origin, careless cache: no private marker for an anonymous request to fixture 3 (an encoded delimiter) (0.0385ms)
✔ careful origin, careless cache: no private marker for an anonymous request to fixture 4 (a normalised dot-segment) (0.034166ms)
✔ careful origin, careless cache: no private marker for an anonymous request to /account (0.032959ms)
✔ careful origin, careless cache: no private marker for an anonymous request to /api/profile (0.0275ms)
✖ careful origin, careless cache: no private marker for an anonymous request to /download/statement.csv (0.653875ms)
✔ careful origin, careless cache: the origin answers 404 to every fixture path, signed in (0.056125ms)
✔ careful origin, careless cache: every response with the private marker says private, no-store (0.059584ms)
✔ careful origin, careless cache: the public stylesheet is served from the cache on the second request (0.074917ms)
ℹ tests 10
ℹ suites 0
ℹ pass 9
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 5.199375
✖ failing tests:
test at deception.test.mjs:25:3
✖ careful origin, careless cache: no private marker for an anonymous request to /download/statement.csv (0.653875ms)
AssertionError [ERR_ASSERTION]: the anonymous request for /download/statement.csv received the private marker
(18 lines cut here: the two values compared, the stack trace and the error properties. The stack trace names files on the computer that ran the lab.)
Exit code: 1
Reading it: with only the origin made careful, nine checks pass and one fails. The download was marked private, no-store, and the careless cache stored it anyway and served it to the request with no cookie.
Step 7. Command: node deception.test.mjs careful careful
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 1 (a file name appended to a private path) (0.694042ms)
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 2 (a path parameter delimiter) (0.049125ms)
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 3 (an encoded delimiter) (0.039375ms)
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 4 (a normalised dot-segment) (0.04125ms)
✔ careful origin, careful cache: no private marker for an anonymous request to /account (0.037458ms)
✔ careful origin, careful cache: no private marker for an anonymous request to /api/profile (0.029125ms)
✔ careful origin, careful cache: no private marker for an anonymous request to /download/statement.csv (0.032042ms)
✔ careful origin, careful cache: the origin answers 404 to every fixture path, signed in (0.045917ms)
✔ careful origin, careful cache: every response with the private marker says private, no-store (0.08075ms)
✔ careful origin, careful cache: the public stylesheet is served from the cache on the second request (0.077ms)
ℹ tests 10
ℹ suites 0
ℹ pass 10
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4.93975
Exit code: 0
Reading it: the careful pair passes all ten checks and the process exits with code 0.
Step 8. Command: node --test
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 1 (a file name appended to a private path) (0.6695ms)
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 2 (a path parameter delimiter) (0.049041ms)
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 3 (an encoded delimiter) (0.040041ms)
✔ careful origin, careful cache: no private marker for an anonymous request to fixture 4 (a normalised dot-segment) (0.036ms)
✔ careful origin, careful cache: no private marker for an anonymous request to /account (0.036542ms)
✔ careful origin, careful cache: no private marker for an anonymous request to /api/profile (0.029458ms)
✔ careful origin, careful cache: no private marker for an anonymous request to /download/statement.csv (0.031917ms)
✔ careful origin, careful cache: the origin answers 404 to every fixture path, signed in (0.045625ms)
✔ careful origin, careful cache: every response with the private marker says private, no-store (0.065458ms)
✔ careful origin, careful cache: the public stylesheet is served from the cache on the second request (0.081458ms)
ℹ tests 10
ℹ suites 0
ℹ pass 10
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 143.601042
Exit code: 0
Reading it: with no version named, the file tests the careful pair, which is what node --test runs when it finds the file by its .test.mjs name. All ten checks pass.
Step 9. Command: node serve.mjs careless careless
careless origin behind careless cache, listening on http://127.0.0.1:63190, process id 40844
sign in at http://127.0.0.1:63190/sign-in as lab-member with the password invented-lab-password-not-real
then open http://127.0.0.1:63190/account/photo.css signed in, and again in a private window
stop it with Ctrl+C, or by its process id
No exit code: the script keeps running until it is stopped. In the recorded run it was stopped with the kill command and the process id it printed, and a check straight afterwards found no process with that id.
Reading it: this is the pairing to practise the browser checks in Part 5 on. The port and the process id differ from run to run.
================================================================
PART 5: BROWSER CHECKS ON YOUR OWN APPLICATION
================================================================
These are steps for you to carry out in your own browser, on an application you own or are authorised in writing to test, signed in as your own test account. Nothing in this part was run for this page. To practise first, start the lab with node serve.mjs careless careless and use the address it prints.
Set up
[ ] Create a test account that holds invented data only, and put a word of your own in its profile, somewhere its account page shows it. That word is your marker.
[ ] Pick one route for each row of the matrix in Part 1.
[ ] Find out which response header your cache uses to report its status. RFC 9211 defines a standard one, Cache-Status. Cloudflare documents one of its own, CF-Cache-Status. For any other product, read its documentation. If your cache sends none, skip the status steps and rely on steps 8 to 11.
Read the headers, signed in
[ ] 1. Open a normal browser window, open the developer tools and choose the network panel.
[ ] 2. Turn off the browser's own cache while the tools are open. In Chrome that is the Disable cache checkbox, which Chrome's documentation says disables the browser cache. What you read next is then not a copy the browser kept.
[ ] 3. Sign in as the test account and load the route.
[ ] 4. Select the request for the route in the list of requests. Chrome's documentation says to select a request under the Name column and open the Headers tab, which has a Response Headers section.
[ ] 5. Write down Cache-Control, Vary and the cache status header. A header that is missing is a result too: write "not sent".
[ ] 6. Load the route again and write down the cache status header on this second request.
[ ] 7. Compare what you wrote with the matrix row.
Ask as a stranger
[ ] 8. Copy the route's full address.
[ ] 9. Open a private window. Check that the site shows you as signed out before you go on.
[ ] 10. Open the developer tools on the network panel, paste the address and load it.
[ ] 11. Read the page. It must not show the marker or anything else from the test account. For a personal route, the correct answers are a sign-in page, a redirect to one, or an error. Then read the cache status header: on a personal route it must not report a hit.
Repeat for the path-confusion addresses
[ ] 12. Build the four fixtures in Part 2 from your own private route, with a file name nobody else would request.
[ ] 13. For each one, load it signed in (steps 3 to 6), then load the same address in the private window (steps 10 and 11).
[ ] 14. Correct result: both windows get a 404 or a redirect, and neither shows the marker. If the private window shows the marker, the route fails. Stop, record the address, the headers and the date, and purge that address from your cache.
When you finish
[ ] Purge every test address you used from the cache, and load each once more in the private window to confirm.
[ ] Keep the filled-in matrix with its dates. It describes your cache configuration on the day you checked.
================================================================
PART 6: THE SAME REGRESSION TEST ON YOUR OWN APPLICATION
================================================================
1. Copy lab.mjs and deception.test.mjs into your project's tests. Leave origin.mjs and cache.mjs behind: your application and your real cache take their place.
2. Replace startLab with the address of a staging copy that sits behind the same cache configuration as production. sendRequest sends plain HTTP to 127.0.0.1, so change it to call your staging address over HTTPS.
3. Replace signIn with however your tests sign in a test account that holds invented data, and PRIVATE_MARKER with a word that only that account's pages contain.
4. Rewrite ROUTE_TYPES with one of your own routes for each matrix row, and FIXTURES with the four addresses from Part 2 built on your own private route. Give each fixture a file name that changes on every run, so that a copy stored by an earlier run cannot answer.
5. Replace the x-lab-cache check with your cache's own status header, or remove that check if your cache sends none.
6. Run it in the pipeline that deploys your application or your cache rules. The Node.js test runner sets the process exit code to 1 if any test fails.
7. Purge the test addresses at the end of each run.What web cache deception is
Web cache deception is a private response ending up in a shared cache.
A signed-in person's browser requests an address. Your server reads that address as their account page and answers with it. The cache in front of your server reads the same address as a public file, such as a stylesheet or an image, and keeps a copy. From then on, a request for that address is answered from the copy, whoever sends it and whether or not they are signed in.
No password was guessed and no access check failed. Two layers read one URL two ways, and the layer that stores things believed the wrong reading.
The attack was described by Omer Gil in a post dated 27 February 2017, Web Cache Deception Attack. His example is a request for a page address with a file name added to it, home.php/non-existent.css. He writes that, depending on its technology and configuration, the server returns the content of home.php for that URL, with the same caching headers and the same content type as the page itself, and that a proxy set to cache static files while disregarding their caching headers identifies that the file has a css extension and caches it.
He gives two conditions for the vulnerability to exist: web cache functionality that is set to cache files by their extensions, disregarding any caching header, and a web server that returns the content of home.php when a page such as home.php/non-existent.css is accessed.
In the same post Gil reports that PayPal was vulnerable, and that the vulnerability is now fixed and was publicly disclosed. The information he lists as open to being leaked includes users' first and last names, account balance, the last four credit card digits, email address and home address.
That is his account of one service in 2017. The post's list of his talks includes Black Hat USA 2017, under the same title.
A research team later measured how far the problem reached. Cached and Confused: Web Cache Deception in the Wild, by Seyed Ali Mirheidari, Sajjad Arshad, Kaan Onarlioglu, Bruno Crispo, Engin Kirda and William Robertson, appeared in the proceedings of the 29th USENIX Security Symposium in August 2020.
It describes web cache deception as an attack in which an attacker tricks a caching proxy into erroneously storing private information and subsequently gains unauthorised access to that cached data. In a crawl the paper dates to 20 to 27 April 2018, its authors found 16 of 295 sites drawn from the Alexa Top 5K, or 5.4%, to contain web cache deception vulnerabilities, and 14 of the 16 leaked personal information of various kinds, including names, usernames, email addresses and phone numbers.
The 295 were the sites that offered sign-in through Google OAuth, which the authors used to create test accounts at scale, so the figure describes that sample.
The paper's diagnosis is the reason this guide treats the cache and the origin together. At its core, the authors write, web cache deception results from path confusion between an origin server and a web cache: different interpretations of a requested URL at these two points lead to a disagreement on the cacheability of a given object.
They add that this does not imply that the origin server and the web cache are each incorrectly configured, and that it is their hazardous interactions as a system that lead to the vulnerability.
Its mirror image, a harmful response stored and served to other visitors, is web cache poisoning, which has a guide of its own.
The two requests in a cache deception attack, and who sends them
In the published accounts, the first request comes from the signed-in person's browser and the second from someone else. Gil writes that the page is cached, and so publicly accessible, once a logged-on user accesses the address, and that the attacker then accesses the page on his own. He adds that websites usually do not require authentication for their public static files, so the cached file needs none either.
Everything on this page keeps both requests in your own hands. The first is sent with your own test account and the second with no session, against your own application or the lab, and the stored copy is your test account's page.
How a cache decides what to store
Whether a response may be stored is decided twice: once by the HTTP standard, which sets the outer limits, and once by the product in front of your site, which has defaults and rules of its own.
Start with the standard. The rules below are from RFC 9111 as it read on 14 November 2026, each with its section number and its requirement word.
- The conditions for storing, section 3. A cache MUST NOT store a response to a request unless every condition on a list holds: the cache understands the request method; the response status code is final; if the status code is 206 or 304, or the must-understand directive is present, the cache understands the status code; the no-store directive is not present in the response; if the cache is shared, the private directive is either not present or allows a shared cache to store a modified response; if the cache is shared, the Authorization header field is not present in the request, or a response directive is present that explicitly allows shared caching; and the response contains at least one of seven things. The seven are a public directive, a private directive if the cache is not shared, an Expires header field, a max-age directive, an s-maxage directive if the cache is shared, a cache extension that allows it to be cached, or a status code that is defined as heuristically cacheable. The section notes that a cache extension can override any of the requirements listed.
- no-store, section 5.2.2.5. The directive indicates that a cache MUST NOT store any part of either the immediate request or the response, and MUST NOT use the response to satisfy any other request. It applies to both private and shared caches.
- private, section 5.2.2.7. The unqualified directive indicates that a shared cache MUST NOT store the response, the response being intended for a single user. It also indicates that a private cache MAY store the response, subject to the constraints in section 3, even if the response would not otherwise be heuristically cacheable by a private cache.
- public, section 5.2.2.9. The directive indicates that a cache MAY store the response even if it would otherwise be prohibited, subject to the constraints in section 3. The RFC's example is that public permits a shared cache to reuse a response to a request containing an Authorization header field.
- s-maxage, section 5.2.2.10. For a shared cache, the maximum age it specifies overrides the maximum age given by max-age or the Expires header field. A shared cache MUST NOT reuse a stale response with s-maxage to satisfy another request until it has been successfully validated by the origin. The directive also permits a shared cache to reuse a response to a request containing an Authorization header field, subject to those requirements on maximum age and revalidation.
- must-revalidate, section 5.2.2.2. Once the response has become stale, a cache MUST NOT reuse it to satisfy another request until it has been successfully validated by the origin. The directive also permits a shared cache to reuse a response to a request containing an Authorization header field, subject to that requirement on revalidation.
- Requests that carry an Authorization header, section 3.5. A shared cache MUST NOT use a cached response to a request with an Authorization header field to satisfy any subsequent request unless the response contains a Cache-Control field with a response directive that allows it to be stored by a shared cache, and the cache conforms to the requirements of that directive for that response. The section names the directives in the specification that have such an effect: must-revalidate, public and s-maxage.
- Heuristic freshness, section 4.2.2. When the origin gives no explicit expiration time, a cache MAY assign a heuristic one. Heuristics can only be used on responses without explicit freshness whose status codes are defined as heuristically cacheable, and on responses without explicit freshness that have been marked as explicitly cacheable, for example with a public directive. RFC 9110 section 15.1 lists 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414 and 501 among the status codes that are heuristically cacheable in that specification, unless the method definition or explicit cache controls indicate otherwise.
What the standard says about cookies, and what it does not
Section 3 has a condition for a request that carried an Authorization header field. It has no condition for a request that carried a Cookie header field. Outside its list of references, the word cookie appears in RFC 9111 in one passage, the note in section 7.3: the Set-Cookie response header field does not inhibit caching, a cacheable response with a Set-Cookie header field can be, and often is, used to satisfy subsequent requests to caches, and servers that wish to control caching of these responses are encouraged to emit appropriate Cache-Control response header fields.
The same section warns that implementation and deployment flaws, often led to by the misunderstanding of cache operation, might lead to the caching of sensitive information that is thought to be private.
Put those together for a web application that signs its visitors in with a session cookie. This is this page's reading, not a sentence from the RFC: a 200 response to a GET request, sent with no Cache-Control header, is not ruled out by anything on section 3's list merely because the request carried a session cookie. The standard leaves it to the origin to say that the response is private.
Vary decides which copy is reused, not whether one is kept
Vary is the origin's way to tell a cache that a response depends on more than the address. RFC 9110 section 12.5.5 says a Vary field that lists header names informs cache recipients 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 of the response has been validated by the origin server.
RFC 9111 section 4.1 gives the cache's side: it MUST NOT use a stored response without revalidation unless all the presented request header fields nominated by the Vary value match those in the original request, and a header field that is absent from one request can only match if it is also absent from the other.
Both rules are about reuse, and Vary does not appear among section 3's conditions for storing. On this page's reading, a response that names Cookie in Vary can therefore still be kept by a shared cache, and Vary is a second signal on a personal response, not the control.
RFC 9110 adds that an origin server SHOULD generate Vary on a cacheable response when it wishes that response to be selectively reused, and that there is no need to send the Authorization field name in Vary.
How Cloudflare, CloudFront and nginx decide, in their own documentation
A product's defaults are not the standard's, and they differ from each other.
Each statement below comes from that product's own documentation as it read on 14 November 2026. It describes that product only, and a rule that you or your host added can change it.
Cloudflare's page on default cache behaviour says Cloudflare only caches based on file extension and not by MIME type, and that the Cloudflare CDN does not cache HTML or JSON by default. The page lists the default cached file extensions. CSS, JS and image formats such as PNG, JPG and SVG are on the list, and so are CSV, PDF, DOC, DOCX, XLS, XLSX and ZIP.
The same page says Cloudflare respects the origin web server's cache headers unless an Edge Cache TTL cache rule overrides them. It does not cache the resource when the Cache-Control header is set to private, no-store, no-cache or max-age=0, when the Set-Cookie header exists, or when the request method is anything other than GET.
It does cache the resource when Cache-Control is set to public with a max-age greater than 0, or when the Expires header is set to a future date. A note adds that Cloudflare does cache the resource even if there is no Cache-Control header, based on status codes.
The same page's Edge TTL section gives the times: when no cache-control directive or expires header is present, the default edge cache time is 120 minutes for 200, 206 and 301 responses, 20 minutes for 302 and 303, and 3 minutes for 404 and 410.
Two of those four Cache-Control values read differently elsewhere in Cloudflare's documentation, and the difference turns on a feature called Origin Cache Control. Its page says Free, Pro and Business customers have the feature enabled by default and cannot disable it, and that customers on the one other plan the documentation lists can enable or disable it.
The table on that page says that with the feature enabled, no-cache and max-age=0 mean Cloudflare caches the response and always revalidates it, and that with the feature disabled it will not cache.
For no-store the table gives the same answer in both columns: will not cache. The page on cache responses agrees for both directives this guide recommends: where the origin returned Cache-Control: no-store or private, it says, these directives prevent caching in either Origin Cache Control mode.
The cache responses page also describes the feature being disabled as the default on that one other plan, which the Origin Cache Control page does not say.
The cache responses page also records what can undo that. Of no-store or a bare private sent in a Cloudflare-CDN-Cache-Control or CDN-Cache-Control header, it says a Cache Rule with an Edge Cache TTL setting that ignores origin cache-control overrides these directives, the same as it does for Cache-Control: no-store.
On signed-in requests the documentation is specific about one header and divided on another. With Origin Cache Control enabled, a response to a request that included an Authorization header is cacheable only if Cache-Control also includes public, s-maxage or must-revalidate; with it disabled, the cache responses page says, Authorization does not by itself prevent caching.
For an origin response that has a Set-Cookie header, the default cache behaviour page says Cloudflare does not cache the resource, while the conditions table on the Origin Cache Control page says that with the feature disabled and the default cache level in use, content may be cached with the Set-Cookie header stripped. Neither of those two pages names a Cookie header on the request as a condition.
Cloudflare reports its decision in a response header of its own, CF-Cache-Status, which its documentation says indicates whether a resource is cached or not. HIT means the resource was found in Cloudflare's cache. MISS means the response is eligible for cache but was not present in the cache at request time, so it was served from the origin.
DYNAMIC means Cloudflare determined at request time that the asset is not eligible for cache. The page lists three cases in which that typically happens: the requested asset is not one of the default cached file extensions, HTML or JSON for example, and no rule instructs Cloudflare to cache it; a Cache Rule with the Bypass cache setting matches the request; or Development Mode is enabled on the zone. BYPASS means the asset was eligible at request time but the origin response was ultimately not cacheable.
Cloudflare has a feature for this attack by name. Its page describes the attack with an example: an origin that serves the dynamic page at /newsfeed for a request to /newsfeed/foo.jpg as well, where, because the path ends in .jpg, Cloudflare caches the response by default.
The steps to enable the feature are to create a cache rule, make the matching requests eligible for cache, and turn on Cache deception armor in the rule's Cache Key setting.
The rule then verifies that a URL's extension matches the returned Content-Type, and when a mismatch that could result in a web cache deception attack is found, Cloudflare does not cache the response.
The page lists two exceptions: a Content-Type of application/octet-stream, where the extension does not matter, and cases it calls unlikely to be attacks, such as .jpg served as image/webp. It also states a condition: Cache Deception Armor depends upon Origin Cache Control, and a Cache-Control header from the origin, or an Edge Cache TTL Cache Rule, may override the protection.
CloudFront's developer guide starts from time, not file type. Its page on cache expiration says that when the origin does not add a Cache-Control max-age directive and the minimum TTL is 0, CloudFront caches the object for the value of the default TTL, and that if you opt out of using a cache policy, the default TTL is 24 hours.
For an origin that adds Cache-Control: no-cache, no-store or private, the page's table has two answers. With a minimum TTL of 0, CloudFront and browsers respect the headers. With a minimum TTL greater than 0, the table says CloudFront caches the object for the value of the minimum TTL, and points to a warning below it.
The warning says that in that case CloudFront uses the cache policy's minimum TTL even if those directives are present in the origin headers, and gives two sub-points: if the origin is reachable, CloudFront gets the object from the origin and returns it to the viewer, and if the origin is unreachable and the minimum or maximum TTL is greater than 0, CloudFront will serve the object that it got from the origin previously. To avoid that, it says to include Cache-Control: stale-if-error=0 with the object.
On this page's reading, the table and the warning leave room for doubt about what is served and when. If a distribution has a minimum TTL above 0 on a path that carries personal responses, treat that as something to test with the two requests described below, since the documentation says the object is kept.
nginx stores nothing until it is told to: the documented default of its proxy_cache directive is off. Once a cache zone is set, the proxy_cache_valid directive sets caching time by response code, and when only a time is given, only 200, 301 and 302 responses are cached.
The module's documentation then says parameters of caching can also be set directly in the response header, with higher priority than the directive. The X-Accel-Expires field sets the caching time of a response, and a zero value disables caching for it.
If that field is absent, parameters of caching may be set in the Expires or Cache-Control fields. If the header includes the Set-Cookie field, such a response will not be cached. From version 1.7.7, a Vary field with the value * means the response will not be cached, and a Vary field with another value means it will be cached taking into account the corresponding request header fields.
The sentence that matters for this guide comes next: processing of one or more of these response header fields can be disabled using the proxy_ignore_headers directive, whose list of fields that can be ignored includes Cache-Control, Set-Cookie and Vary. The page does not say which Cache-Control directives stop a response being cached, so confirm how your own configuration treats private and no-store by test.
The framework behind the cache matters as much as the cache. Next.js is one example: its self-hosting guide says dynamically rendered pages set a Cache-Control header of private, no-cache, no-store, max-age=0, must-revalidate to prevent user-specific data from being cached, in both the App Router and the Pages Router, and that Next.js sets public, max-age=31536000, immutable on truly immutable assets, the files with a hash in their names, which cannot be overridden.
Its section on usage with CDNs says a page will include Cache-Control: private when dynamic APIs are accessed, and Cache-Control: public if the page is fully prerendered to static.
Three products, three starting points: a list of file extensions, a default time when the origin sets none, and nothing at all until a cache zone is configured. In all three, the documentation describes a setting on the cache's side that can change what the origin's header does: an Edge Cache TTL rule on Cloudflare, a minimum TTL above 0 on CloudFront, proxy_ignore_headers on nginx.
That is why the checks later on this page end with an anonymous request, not with reading a header.
Path confusion caching: why one URL means two things
A URL looks like one fixed thing, and the standards say otherwise.
RFC 3986, the URI standard, says in section 3.3 that apart from dot-segments a path segment is considered opaque by the generic syntax, and that applications often use the reserved characters allowed in a segment to delimit subcomponents of their own.
RFC 9110 says HTTP does not require the use of a specific method for determining whether two URIs are equivalent, and gives the example that a cache key might be compared as a simple string, after syntax-based normalisation, or after scheme-based normalisation.
On this page's reading, the layer that routes a request and the layer that stores the response are each left free to read the address their own way.
Path confusion is the name the 2020 USENIX paper gives to the result. Martin Doyhenard's research for PortSwigger, Gotta cache 'em all: bending the rules of web cache exploitation, published on 8 August 2024, puts the mechanism in one sentence: if the cache and the application server's parsers are different, it may be possible to use a discrepancy to change the meaning of the URL.
The USENIX authors set out the two properties such an address needs. The web server must interpret it as a request for a non-cacheable page with private information, and it should trigger a successful response; and an intermediate web cache must interpret the same URL as a request for a static object matching the caching rules in effect.
The four cases below are the fixtures in the lab on this page. In each, the lab's careless origin answers with the account page and its careless cache stores the answer. They illustrate four kinds of disagreement, and they are not a list of every kind.
The address is /account/photo.css. This is Gil's original case, which the USENIX paper calls the Path Parameter technique. An origin reads it as the account page when its routing matches on how a path begins and tolerates what follows.
The latest edition of the OWASP Web Security Testing Guide shows how small the cause can be: a Django URL pattern written with a regular expression that, the guide says, is not the correct one, so that opening /dashboard/none.js can display the user's dashboard information.
A cache with a rule on file extensions reads the same address as a stylesheet. In the lab, the careless origin treats a defined path as answering for anything underneath it.
The address is /account;photo.css. RFC 3986 section 3.3 notes that the semicolon and equals characters are often used to delimit parameters and parameter values applicable to a segment, and gives name;v=1.1 as an example of such a segment. Some frameworks act on that.
The first of the four origin delimiters the 2024 paper lists is the semicolon in Spring, where, it says, matrix variables can be included in each path segment and are not interpreted as part of the absolute path, so that /MyAccount;var1=val has the path /MyAccount.
The other three on its list are the dot in Ruby on Rails, the encoded null byte in OpenLiteSpeed, and the encoded newline byte in nginx when it is configured to rewrite the request path.
The paper adds that cache servers often do not use delimiters aside from the question mark. In the lab, the careless origin drops everything from a semicolon to the end of each segment, and the careless cache does not.
The address is /account%3Fphoto.css, where %3F is a percent-encoded question mark. RFC 3986 section 2.2 says URIs that differ in the replacement of a reserved character with its corresponding percent-encoded octet are not equivalent, and section 2.4 says that when a URI is dereferenced, the components and subcomponents significant to the scheme-specific dereferencing process must be parsed and separated before the percent-encoded octets within those components can be safely decoded, as otherwise the data may be mistaken for component delimiters.
A layer that decodes first and splits second turns %3F into a real question mark and treats what follows as a query string.
The USENIX paper tested five techniques of this family: the original, plus an encoded newline, an encoded semicolon, an encoded pound sign and an encoded question mark. In its second experiment, run in July 2019 over 340 sites, it found 25 vulnerable sites, 11 of which were exploitable only with one of the variations and not with the original technique.
In the lab, the careless origin decodes the whole request target before it looks for the question mark.
The address is /static/..%2Faccount, where %2F is a percent-encoded slash. RFC 3986 defines the path segments . and .. as dot-segments in section 3.3, describes a routine for removing them in section 5.2.4, and says in section 6.2.2.3 that some deployed implementations fail to remove dot-segments when they occur in non-relative paths.
An origin that decodes the slash and then resolves the dot-segment reads /static/../account as /account. A cache that does neither sees an address under /static/.
The 2024 paper describes this arrangement for caches with a rule on a path prefix, which it calls a static directory rule: when the origin server normalises the path before mapping the endpoint and the cache does not normalise the path before evaluating its rules, a segment can be added that only the origin processes.
Its note on why the dot-segment is encoded sits under the neighbouring technique, in which a path traversal segment is hidden after a delimiter: otherwise, it says, the browser will resolve it and will not forward the original path.
In the lab this is the one fixture that does not end in a file extension, and the careless cache stores it under its second rule, anything that starts with /static/.
Dot-segments in this guide stay inside the site's own tree of paths. Using them to reach files outside the folder an application serves is path traversal, a different weakness with its own guide.
Four controls: the origin first, the cache second
Four controls close the gap, two at each layer.
They are listed in the order to apply them.
- The origin marks every personal response so that no shared cache may store it. This page's advice is Cache-Control: private, no-store on each one.
- The origin refuses paths it does not define. A request for /account/photo.css gets a 404 or a redirect, not the account page.
- The cache decides from the origin's headers and the response's content type, not from a file extension or a folder name in the URL alone.
- Both layers read a URL the same way.
Each control has a source. Gil's 2017 post gives three mitigations: configure the cache mechanism to cache files only if their HTTP caching headers allow, which he says will solve the root cause of the issue; if the cache component provides the option, configure it to cache files by their content type; and configure the web server so that for a page such as home.php/non-existent.css it does not return the content of home.php, responding instead with, for example, a 404 or 302.
ASVS 5.0 has a requirement on the same ground, 14.2.5, at Level 3: caching mechanisms are configured to only cache responses which have the expected content type for that resource and do not contain sensitive, dynamic content, and the web server should return a 404 or 302 response when a non-existent file is accessed rather than returning a different, valid file.
The requirement says this should prevent web cache deception attacks. The latest edition of the OWASP testing guide supplies the fourth control in its remediation list: normalise paths consistently, and to the same canonical form, in every component that makes a security decision based on the path.
Both directives keep a response out of a shared cache, by different definitions. private is addressed to shared caches: RFC 9111 section 5.2.2.7 says the unqualified directive indicates that a shared cache MUST NOT store the response, and that a private cache MAY, subject to the constraints in section 3. no-store is addressed to every cache: a cache MUST NOT store any part of the request or the response, and the RFC says the directive applies to both private and shared caches. For a CDN or proxy that follows the standard, either one settles the storing decision.
This page recommends sending both on personal responses. You do not control every cache between your server and the visitor, and a second directive costs nothing. ASVS 5.0 requirement 14.3.2, at Level 2, asks for Cache-Control: no-store so that sensitive data is not cached in browsers.
RFC 9111 section 5.2.2.7 says the unqualified private directive indicates that a private cache MAY store the response, subject to the constraints in section 3. On this page's reading, private sent alone therefore permits the browser caching that the ASVS requirement is there to prevent.
And the defence section of the 2024 PortSwigger paper recommends this pair: mark all dynamically generated responses with a Cache-Control header set with the no-store and private directives.
Neither directive is a lock. RFC 9111 says of no-store that it is not a reliable or sufficient mechanism for ensuring privacy: in particular, it says, malicious or compromised caches might not recognise or obey it, and communications networks might be vulnerable to eavesdropping.
It says of private that the word only controls where the response can be stored and cannot ensure the privacy of the message content. The USENIX authors saw the everyday version. Among the vulnerable sites they found, pages carrying headers such as Cache-Control: no-store were cached regardless, which they took to suggest that site administrators use the configuration controls web caches provide to override header-specified caching policies. A header is an instruction. Whether your cache follows it is something to test.
no-cache is a different instruction. RFC 9111 section 5.2.2.4 says that the directive, in its unqualified form, indicates that the response MUST NOT be used to satisfy any other request without forwarding it for validation and receiving a successful response. On this page's reading, that leaves a cache free to keep a copy. The sensitive data exposure guide sets out which directive addresses which store.
The origin's other half of the fix is routing. Every path-confusion case on this page ends the same way at a careful origin: the path is not one the application defines, so the answer is an error or a redirect, and there is no private page to store. ASVS 5.0 requirement 14.2.5 names the two answers, 404 or 302.
How to get there is this page's advice: match routes exactly instead of with patterns that tolerate extra segments, do not strip parameters or trailing file names before routing unless the application uses them, and send the error itself with no-store and nothing about the signed-in person in it.
The lab's careful origin does this in the smallest way possible. It takes the raw path, decodes nothing, and answers only when the path equals one on its list, and all four fixtures then return 404 to the signed-in test account.
A rule that stores everything ending in .css asks the URL a question only the response can answer. The cache-side fix is to let the origin's Cache-Control decide, and to check that the content type fits the extension where the product can. Gil's second mitigation and the first half of ASVS 5.0 requirement 14.2.5 both ask for the content type check, and Cloudflare's Cache Deception Armor is that check as a product feature.
The 2024 PortSwigger paper adds a step that is easy to miss: verify that the cache rules do not have priority over the Cache-Control header.
ASVS 5.0 has a broader requirement for the same layer. Requirement 14.2.2, at Level 2, asks that the application prevents sensitive data from being cached in server components, such as load balancers and application caches, or ensures that the data is securely purged after use.
The last control removes the disagreement itself. Where you control both layers, decide whether semicolons, encoded slashes and dot-segments mean anything in your application, and configure the cache and the origin to treat them identically. The testing guide's remediation list says to perform security-relevant path matching after normalisation and decoding, not on the raw request line, and to normalise in every component that makes a security decision based on the path.
The lab's careful pair agrees in the simplest way, by not normalising at all: the cache forwards and keys the raw request target, and the origin matches it exactly.
Where the cache cannot be made to agree, the 2024 paper has a fallback. If a CDN cannot be configured so that its cache rules do not take priority over Cache-Control, it says to consider disabling the caching rules, or to avoid using an origin server or framework that parses the URL differently to the CDN.
It is tempting to stop at the cache: turn on the product's protection and leave the application alone. The lab shows what that leaves behind. With the careless origin behind the careful cache, the anonymous request received the private marker in 0 of 4 fixtures, because the cache would not store a text/html response under a .css address, or a response the origin had not marked public.
The origin was unchanged. It still answered all four addresses with the account page, status 200, with no Cache-Control header, and the regression test still failed three of its ten checks.
An origin left like that has three problems. Its protection is one product's configuration on one day: each of the three products above documents a setting that can change what the origin's header does, and Cloudflare's own page says a Cache-Control header from the origin or an Edge Cache TTL rule may override Cache Deception Armor.
Its responses carry no instruction for any other cache they pass through, and a heuristically cacheable status such as 200 is one of the things section 3 of RFC 9111 accepts in place of an explicit instruction.
And the cache in front of it cannot do its real job: in the same lab run the public stylesheet was not served from the cache on the second request, because the origin had never said it was public.
The quick way to get that performance back is a rule that caches by file extension, which is the careless cache again.
The reverse pairing fails differently, which is why the cache comes second and is not optional. With the careful origin behind the careless cache, all four fixtures returned 404, so none of them put anything private in the cache. But the lab's statement download lives at an address that really does end in .csv.
The careful origin marked it private, no-store, the careless cache did not read the header and stored it by extension, and the request with no cookie received the test account's statement. An origin cannot protect a response from a cache that does not read its headers.
Cache deception testing: every route type, both requests
Testing for web cache deception is two requests and a comparison.
Send a request for an address with a signed-in test account. Send the same address again with no session. If the second response contains anything that belongs to the test account, the route fails, whatever the headers said.
The headers and the cache status explain a result, and they do not replace the second request: the USENIX authors found that the presence of cache headers was an unreliable indicator of whether a resource is cached.
Run these checks only on an application you own or are authorised in writing to test, signed in as a test account that holds invented data. A check that finds the problem has placed a copy of that account's page in a shared cache, where it stays until it expires or is purged. Keep that copy harmless and easy to find:
- Use staging where it sits behind the same CDN or proxy configuration as production.
- Use a test account whose pages hold nothing real, and put a marker word of your own in its profile so you can search responses for it.
- For the path-confusion addresses, use a file name nobody else would request, different on every attempt, so the only stored copy sits at an address only you know.
- Send the second request yourself, from a private browser window or a command-line client with no cookies. Nobody else needs to open anything.
- Purge each test address when you finish, then request it once more to confirm the copy has gone.
- Check your host's and your CDN's testing terms before you start.
Test more than the account page. The matrix on this page has a row for each of six route types: a public static file, a public page, a page that differs by signed-in person, an API response with personal data, a download and an error page.
For each row it gives who may see the response, the Cache-Control the origin should send, what Vary should name, whether a shared cache may store it, what the cache status should read on a second request and what an anonymous request must get back. A cell names its source where it has one; every other expected value is this page's advice.
Downloads deserve particular attention, because their own addresses end in file extensions. A statement at /download/statement.csv needs no path confusion to look static, and CSV, PDF, XLSX and ZIP are all on Cloudflare's list of default cached file extensions. On such a route the origin's header is what tells the cache that the file is personal.
A cache can report what it did with a request in a response header. There is a standard for this, RFC 9211, The Cache-Status HTTP Response Header Field, published in June 2022. Each member of the header's list represents a cache that handled the request. A hit parameter, when true, indicates that the request was satisfied by the cache, a fwd parameter indicates that the request went forward towards the origin and why, and a stored parameter indicates whether the cache stored the response.
The RFC's example of a minimal cache hit is Cache-Status: ExampleCache; hit.
It also says caches determine when it is appropriate to add the header: some might add it to all responses, whereas others might only do so when specifically configured to, or when the request contains a header field that activates a debugging mode.
Products also have status headers of their own, which are not that standard. Cloudflare's is CF-Cache-Status, with the values described above. The lab's cache has one too, x-lab-cache, invented for this page. Whichever header your product sends, this page's expected reading is the same: a hit on the second request for a public static file, and no hit on a personal route.
RFC 9211 carries a caution for production sites: attackers can use the information in Cache-Status to probe the behaviour of the cache, and the header can be omitted, or sent only when the client is authorised to receive it.
You need a browser, a test account and the address of one route from each row of the matrix. The full steps are in part 5 of the asset on this page.
- Open the developer tools and the network panel, sign in as the test account and load the route. Chrome's documentation says to select a request under the Name column and open the Headers tab, which has a Response Headers section.
- Read Cache-Control, Vary and your cache's status header, and write them in the matrix row.
- Tick the Disable cache checkbox while you do this. Chrome's documentation says it disables the browser cache. What you read is then not a copy the browser kept.
- Load the route a second time and read the status header again.
- Paste the address into a private window where you are signed out, and confirm that what comes back is a sign-in page, a redirect or an error, not the test account's page.
- Repeat the last step for each path-confusion address built from your own private route.
The OWASP Web Security Testing Guide has a test for this in its latest edition, the one its site says represents the latest contributions and may frequently change: Path Confusion, with the id WSTG-CONF-13. Its summary gives web cache deception as the example of what a mismatch between an origin and a CDN allows, and its black-box steps suggest requesting a dashboard path with /non.js added.
Version 4.2, which the site labels stable, has no such test: its configuration chapter lists eleven tests, and none of them is about path confusion.
The lab: an invented origin behind a cache written for this page
The lab on this page is an illustration.
It is an invented origin, Lab Ledger, with a sign-in, an account page, an API route, a statement download and a stylesheet, and in front of it a small shared cache written for this page that keeps what it stores in memory. It shows the pattern this guide describes.
It does not show how any real CDN, proxy or framework decides anything, and its cache is not an implementation of RFC 9111: it has no clock, so nothing expires, and it does no validation and no Vary matching.
Each side has a careless and a careful version. The careless origin answers the account page for any path that resembles /account once decoded and trimmed, and sends no Cache-Control header. The careful origin answers only the exact paths it defines and marks every personal response private, no-store. The careless cache stores any GET response whose path ends in one of four file extensions or starts with /static/, without reading the response.
The careful cache stores a 200 response only when the origin said public, not when it said private or no-store, not when the response has a Vary header, and, when the path ends in one of the lab's four static file extensions, only when the content type is the one the lab lists for that extension; a path with no such ending gets no content-type check. Requiring public makes it stricter than the standard.
Apart from each other, the eight files import only node:assert/strict, node:crypto, node:http and node:test, and the lab installs no packages. Both servers listen on 127.0.0.1 and ask for port 0. The Node.js documentation says the HTTP server's listen() is identical to the one in its net module, where port 0 makes the operating system assign an arbitrary unused port.
The one account, lab-member, has an invented password that is no product's default, and the private marker is a line of text made up for this page.
The run recorded in the asset was made on Node.js 26.0.0 on macOS, the only version and the only system it was run on. The Node.js documentation lists the node:test module as stable since v20.0.0.
The fixture script signs in as the test account, requests each of the four addresses through the cache, then requests the same address with no cookie. Across the four pairings of origin and cache it printed these results.
- Careless origin, careless cache: the anonymous request received the private marker in 4 of 4 fixtures. Each signed-in response was stored, three because the address ended in .css and one because it started with /static/, and each request with no cookie was a HIT.
- Careless origin, careful cache: 0 of 4. The origin still answered all four with the account page. The cache did not store them, and the requests with no cookie were redirected to the sign-in page.
- Careful origin, careless cache: 0 of 4. The origin answered 404 with no-store, and the careless cache stored the 404 pages anyway, so the requests with no cookie were HITs on an error page with nothing private in it.
- Careful origin, careful cache: 0 of 4, and nothing stored.
The matrix script, and the leak the fixtures do not show
A second script runs the same two requests over the lab's own six route types, one for each row of the matrix. It found a leak that needs no path confusion: under the careless cache, the statement download was stored and served to the request with no cookie, private marker included, with either origin.
Under the careful pair, the stylesheet and the home page were HITs on the second request and the three personal routes were not stored.
The regression test
The test file runs ten checks against one pairing. Seven are that a request with no cookie receives no private marker: the four fixtures and the three personal routes. One is that the origin answers 404 to every fixture address.
One is that every response carrying the marker says private, no-store. The last is that the public stylesheet is still served from the cache on the second request, so that a fix which simply turned caching off would not pass.
Seven of the ten failed on the careless pair. Three failed with only the cache made careful, one failed with only the origin made careful, and all ten passed on the careful pair. The Node.js documentation says that if any tests fail, the process exit code is set to 1.
A pipeline step that treats a non-zero exit code as a failure then stops. Part 6 of the asset describes how to point the same checks at your own application.
Neighbouring guides, and where a Clever Ops test fits
Two more guides sit beside this one.
The cookie security guide covers the attributes of the session cookie itself, which decide where a browser sends it and not what a cache does with the response. The security misconfiguration guide covers settings that drift between what was tested and what is running, and a cache rule changed in a dashboard is a setting of that kind.
Clever Ops tests websites, custom web applications and their APIs. A web application and API penetration test is run from test accounts in every role the scope names, and 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, tell us at the scoping call which CDN or reverse proxy sits in front of the application, who controls its settings, and whether a staging copy runs behind the same cache configuration.
Cache tests run on staging, or with a cache key unique to the test on production, so that test responses are not stored where real visitors are served from.
Each finding comes with evidence, a fix and the criteria the retest will use. A report is evidence for your decisions, not a certificate, and it is not monitoring: a cache rule added the week after the test is outside what it can speak to.
If Clever Ops built or hosts your application, 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 a shared cache, such as a CDN, storing one signed-in person's private page because it took the address for a public file. The next request for that address gets the stored copy, with or without a session. Omer Gil described the attack in February 2017, and a 2020 USENIX Security paper traces it to path confusion: the origin server and the cache interpreting the same URL differently.
There are two requests. First, a signed-in person's browser requests an address such as /account/photo.css. The origin answers it with the account page, and the cache stores the response because the address looks like a stylesheet. Second, a request for the same address arrives with no session, and the cache answers it from the stored copy. In the checks on this page you send both requests yourself, using your own test account.
It tells every cache that follows the HTTP standard not to store the response: RFC 9111 says a cache MUST NOT store any part of it. Whether your cache follows it depends on the product and its rules. Cloudflare's documentation says no-store and private prevent caching in either of its Origin Cache Control modes. CloudFront's says that with a minimum TTL above 0 it uses that minimum even if those directives are present, and adds two sub-points: if the origin is reachable, CloudFront gets the object from the origin and returns it to the viewer, and if the origin is unreachable and the minimum or maximum TTL is greater than 0, it will serve the object it got from the origin previously. nginx's proxy_ignore_headers directive can disable processing of Cache-Control. Send the header, then confirm with a request that has no session.
It is two components reading one URL differently. The latest edition of the OWASP testing guide describes it as routers, proxies, caches, web application firewalls (WAFs) and the application itself disagreeing on what a given URL path identifies, because of path normalisation, trailing slashes, case sensitivity or encoding differences. This page uses four examples: a file name appended to a private path, a semicolon parameter, an encoded question mark, and an encoded slash with a dot-segment.
In the person's own browser, the standard allows it: RFC 9111 section 5.2.2.7 says the unqualified private directive indicates that a shared cache MUST NOT store the response and that a private cache MAY, subject to the constraints in section 3. Whether you want that is a separate decision, and ASVS 5.0 requirement 14.3.2 asks for Cache-Control: no-store so that sensitive data is not cached in browsers. In a shared cache, a response that differs by signed-in person has no place.
Use a test account that holds invented data, on staging if it sits behind the same cache configuration. Request the route signed in, then request the same address with no session, and check that nothing from the test account comes back. For path-confusion addresses, use a file name nobody else would request, so that any stored copy is at an address only you know, and purge it afterwards. Test only a site you own or are authorised in writing to test.
Not under the HTTP standard. RFC 9111's conditions for storing a response include one for requests that carry an Authorization header and none for requests that carry a cookie, and the RFC notes that a Set-Cookie header on the response does not inhibit caching. Products add rules of their own, so read your product's documentation and mark personal responses private, no-store.
One layer is then checking. In the lab on this page, a careful cache in front of a careless origin stopped all four fixtures, yet the origin still answered each with the account page and no caching header, and three of the regression test's ten checks still failed. Cloudflare's documentation says a Cache-Control header from the origin or an Edge Cache TTL rule may override its Cache Deception Armor. Fix the origin first, then keep the cache's check on.
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.