Web cache deception: when the cache stores a page meant for one person

Web cache deception is an attack in which a shared cache is led to store a private, dynamic response as if it were a static file, so that someone other than the account owner can request the stored copy. It needs no flaw in the page itself. It needs a cache and an origin that read the same URL in two different ways.

Section Web attacks Updated Standard RFC 9111

Quick facts

Origin of the name
Described by Omer Gil in Web Cache Deception Attack, published 27 February 2017
What goes wrong
Cache and origin disagree about the URL, so a dynamic response is treated as cacheable (PortSwigger Web Security Academy)
Shared cache
A cache that stores responses for reuse by more than one user (RFC 9111 section 1)
Headers that stop it
private keeps a response out of shared caches; no-store keeps it out of every cache (RFC 9111 section 5.2.2)
Sensitive data
RFC 9111 section 7.3 warns that deployment flaws can lead to caching information “thought to be private” (section 7.3)
Main fix
Mark every personal or dynamic response Cache-Control: private or no-store, and do not let a cache rule override that header

Definitions follow RFC 9111 (HTTP Caching), the PortSwigger Academy topic and Gil’s original article. Header semantics were also checked against MDN’s Cache-Control reference.

How cache deception works

Picture a site with a page that shows the signed-in user’s account details. The address of that page is dynamic: the application builds the response from the session cookie. Now picture a CDN or reverse proxy in front of the site, configured to cache anything that looks like a static file, say by its ending or by the directory it sits in.

Gil’s article describes the trap as a mismatch. The application is lenient about the address it accepts and still returns the account page when extra text is appended to the path. The cache is lenient in a different way: it sees a file-style ending and files the response away as static. Two readings of one address, and the private page ends up in a store that other people can query.

The sequence has three steps:

  1. A victim loads a crafted address. The attacker needs the victim’s browser to make the request while the victim is signed in, typically by getting them to follow a link.
  2. The origin answers with the victim’s own page. The cookie identifies the victim, so the response contains their data, and the cache stores it.
  3. The attacker requests the same address. No session is needed. The cache sees a stored copy under a matching key and returns it.

The stored page can be anything the origin built for one person: a profile, an order, a settings screen. The attacker never touches the victim’s account directly; the cache hands over what it was given.

Why the cache is fooled

A cache needs two decisions to go wrong. It must choose to store the response, and the response must carry nothing that tells it not to.

The storing decision

RFC 9111 section 3 lists what a cache requires before it stores a response. One accepted signal is an explicit directive such as max-age; another is a status code the standard marks as heuristically cacheable. In the second case section 4.2.2 lets the cache assign its own expiration time. A response with no caching headers at all can therefore be stored by default.

CDNs and proxies often add configurable rules on top. The Academy groups the common ones into three kinds: rules matching a static file extension such as .css or .js, rules matching a static directory prefix such as /static or /assets, and rules matching an exact file name such as robots.txt or favicon.ico. Each rule is a promise that matching paths hold public files. Cache deception is what happens when the promise is false for some path.

Where the two readings diverge

The Academy traces most cases to discrepancies in how cache and origin map a URL to a resource. Typical gaps are delimiter characters and the handling of encoded dot-segments. The Academy’s topic walks through each class; this page does not reproduce request strings. For defenders the point is simple: if two components parse paths differently, a rule on one of them can be matched by a request the other reads as something else. The same family of parsing disagreement drives path traversal.

The missing header

A response that says Cache-Control: private should never reach a shared cache’s store, and no-store forbids any cache from keeping it. Gil’s attack worked against caches that decided by file extension and paid no attention to the caching headers. A cache rule that overrides the origin’s header removes the one signal that could have saved the page, which is why the Academy advises configuring the CDN so that rules do not override Cache-Control.

Two further points from the standards. First, a Set-Cookie header does not stop caching; RFC 9111 section 7.3 notes that a cacheable response carrying it can be, and often is, used to answer later requests. A session cookie on the response is not protection. Second, a login does not make a page uncacheable by itself. Requests that carry an Authorization header get special treatment, but a cookie-based session does not.

Deception versus poisoning

The two names sound like one attack and behave like opposites. In web cache poisoning the attacker plants a harmful response and many visitors receive it. In deception the attacker plants nothing. The victim’s own legitimate response is stored, and the attacker reads it.

Web cache deception and web cache poisoning compared
Web cache deceptionWeb cache poisoning
What gets storedA private response built for one victimA response made harmful by attacker input
Who is harmedThe victim whose data was storedLater visitors who receive the stored response
Attacker needsThe victim to request a crafted addressAn input the cache ignores but the application uses
Root causeCache and origin read one URL differentlyGap between the cache key and what the app reads
Main fixprivate or no-store on dynamic responsesKey or remove the input; limit what is cacheable

Both attacks shrink when only genuinely static responses can enter a shared cache. They also meet at the proxy, because the reverse proxy that holds the cache is usually where path handling and header rewriting happen. The related session hijacking page covers what an attacker can do when a session identifier is leaked, which is one thing a stored page can contain.

Checking your own pages

The audit is a short list of questions, and none requires an attack.

  • Which routes return personal data? Account pages, order histories, settings, API endpoints that return the current user’s records. Each should have a deliberate Cache-Control value.
  • What do the response headers say? With your own test account on a staging copy, request each route and read the headers. Look for private or no-store, and for any cache-status header your CDN adds; its name and values are vendor-specific, so use that product’s documentation.
  • What does the cache believe is static? Read the rules: extensions, directory prefixes, file names. Ask whether any dynamic route could sit under one of them.
  • How lenient is the origin? Does a dynamic route answer successfully when the path carries extra segments or a file-style ending? Gil’s advice is that it should not.

Do this on staging, with your own accounts.

How to prevent web cache deception

The Academy and Gil agree on the core. The steps below combine their advice with the header definitions in RFC 9111 and MDN.

  1. Mark dynamic and personal responses. Send Cache-Control: private (a shared cache must not store the response) or no-store (no cache may store any part of the exchange) on everything built for one user. MDN advises private for personalised content, especially responses after login and sessions managed with cookies.
  2. Prefer no-store for the most sensitive pages. no-cache is not a substitute: it lets caches store the response and only requires revalidation before reuse.
  3. Stop cache rules from overriding the header. Configure the CDN so extension, directory and file-name rules respect the origin’s Cache-Control.
  4. Cache by content type, not by ending. Gil suggests this where the cache supports it. An HTML page answering a request for a stylesheet-looking path would then not be stored as a stylesheet. The response type comes from the Content-Type header (RFC 9110 section 8.3), which the origin controls.
  5. Make the origin strict about paths. Gil suggests that a dynamic page requested with a static-file suffix should return an error such as 404, or a redirect, rather than the dynamic content.
  6. Align path handling. The Academy asks you to verify that the origin and the cache interpret URL paths the same way, including delimiters and encoded dot-segments.
  7. Turn on built-in protection. The Academy recommends activating any protection your CDN offers against cache deception. What that means depends on the product and is described in its documentation; this page makes no claim about Bridge CDN’s cache behaviour.

Be careful with public. It tells a cache that it may store a response it would otherwise skip, and MDN notes it causes responses to requests with an Authorization header to be stored in shared caches. Never add it to a route that returns user-specific data.

OWASP’s Testing for Browser Cache Weaknesses covers the browser-side version of the same worry, sensitive pages recoverable from a local cache. It is a different cache, and it asks testers to look for Cache-Control: no-cache, no-store on such pages.

Where a WAF helps and where it does not

A WAF reads requests as they arrive and can match them against rules. For cache deception that gives a narrow set of uses, and an honest account has to start with what the filter cannot do.

  • The response is the problem, and the filter works on requests. The leak is a private page stored under a public-looking path. Whether it is stored depends on response headers and cache rules that a request filter does not control.
  • The crafted request looks ordinary. A path with a file-style ending is valid HTTP, and legitimate sites serve such paths. A rule that refuses every one would break pages that should work.
  • The attacker’s fetch may never reach the filter. If the shared cache answers from its store, the request can be served before the filter sees it, depending on where the cache sits.

Where it can help: a rule written for your own routes, for instance flagging requests where a known dynamic path is followed by a static-style ending, shows how often such requests occur and from where. That is useful evidence before you tighten the origin’s path handling, though it does not replace it. Fixing the headers and the cache rules stays with your application and cache configuration. A web application firewall filters requests; it does not rewrite your code or your cache policy.

Bridge WAF has three modes. In monitor mode matches are recorded and every request is still served, so the activity log shows which requests would have matched before any is refused. Start there, read the log, and only then move a rule to block. Expect some matches to be ordinary traffic; the page on false positives covers the review, and monitor mode explains the workflow.

Questions

What is web cache deception?

Web cache deception is an attack that tricks a shared cache into storing a private, dynamic response, such as an account page, by making it look like a static file. The attacker then requests the stored copy. It was described by Omer Gil in 2017.

What is the difference between web cache deception and web cache poisoning?

Deception stores the victim’s private response so the attacker can read it. Poisoning stores a harmful response so that other visitors receive it. In deception the data of one user leaks; in poisoning many users get attacker-chosen content.

How do you prevent web cache deception?

Send Cache-Control: private or no-store on every dynamic and personal response, and configure the cache so its rules do not override that header. Where possible, cache by content type rather than file extension, and make the origin return an error for static-style endings on dynamic pages.

Is Cache-Control: no-cache enough to stop it?

No. no-cache lets a cache store the response and only requires revalidation before reuse. To keep a response out of a cache use no-store, or private to keep it out of shared caches.

Can a WAF stop web cache deception?

Only in part. A WAF can record or refuse requests that match a rule you write for your own routes, but the leak depends on response headers and cache rules that a request filter does not control. The lasting fix is in Cache-Control headers and cache configuration.