A Shared Cache Reuses One Response Across Requests
A property manager labels each parcel locker with the street address, 14 Mill Street. The apartment number is missing. The first package is for Flat 2; the next person who asks for 14 Mill Street gets it, even from Flat 1. The locker did what its label said. The label was the bug.
The edge returns bytes by string, not by person. It does not recognize Alice; it computes a key from the request and serves whatever is stored under it. Alice and Bob both request /account with different session cookies, the default key is identical, and whoever is stored first is served to both.
The vocabulary names the controls:
- A shared cache stores one response for many users; the Cloudflare edge is shared, a browser cache is private.
- A cache key is the string used to store and find a representation. Same key means same bytes.
- A representation is the stored body plus the headers that survived storage.
- An unkeyed input changes the representation but is absent from the key.
- A principal is the identity whose data appears in the response.
- A hit returns a fresh entry; a miss asks the origin; a bypass does not store or reuse.
The key is a sharing set
The key is a data-sharing boundary, not a lookup optimization. Every request that maps to key(request) joins the same sharing set. For every input that changes the representation, either include it in the key or ensure it cannot change the representation. Partition or sanitize, and know which one you chose.
Default key: the full URL, the Origin header, method-override headers, and forwarding headers such as x-forwarded-host (Cache keys). Not in the key: the Cookie and Authorization headers. That is a starting point, not a privacy policy.
The plan boundary is part of the design. Custom header, cookie, host, and user fields such as country and language are Enterprise-only. Free, Pro, and Business can ignore or sort query strings, cache by device type, and enable Cache Deception Armor, but cannot add a cookie or arbitrary header to the key (Cache keys availability). On those plans, a personalized page should bypass, not get a clever key. At writing time, Cache Rules include 10 rules on Free, 25 on Pro, 50 on Business, and 300 on Enterprise (Cache Rules).
Ask three questions: may this request use the cache, what key identifies the object, and may this response be stored. Figure 1 shows the sequence and the refusal branch.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Alice: GET /account
Cookie: session=alice"] --> K["Build key
scheme + host + path + query"]
B["Bob: GET /account
Cookie: session=bob"] --> K
K --> F{"Fresh entry
under this key?"}
F -->|"yes"| H["HIT: return stored bytes"]
F -->|"no"| O["Origin renders
for this request"]
O --> S{"Response storable?
Cache-Control, Set-Cookie, Vary"}
S -->|"yes"| W["Store under the same key"]
S -->|"no"| X["BYPASS: serve once,
store nothing"]
W --> H
H --> R["Every later request
with this key gets these bytes"]
X --> Y["Only this requester
sees the response"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class A,B,O primary;
class K,F,W,R secondary;
class H,S,Y ok;
class X danger;
Figure 2 redraws the request as layers: clients outside the trust boundary, the edge owning the key and entry, the origin deciding what the response means.
The cache makes an equality decision, not a trust decision. Security lives in the key, in storability, or in the application's refusal to vary.
Shared caches also stack. A browser cache reuses a response for one user; a corporate proxy reuses it for a department; an origin reverse proxy reuses it for every request that reaches it; a Worker cache reuses it inside one data center. A fix at the Cloudflare edge does not fix a Varnish layer behind it. Inventory every cache between the principal and the database, and ask each one the same two questions: what is the key, and what makes this response storable?
Unkeyed Inputs Can Change a Cached Representation
An unkeyed input is request data that changes the body but not the key. The common cases are ordinary: a custom header, a cookie, a language preference, a GET body, or a path the edge normalizes differently from the origin.
A header can change the body without changing the key. Take /quote: Alice sends a currency header and gets a dollar total; Bob sends another and should get the euro total. The key is the URL, so Alice's response is stored and Bob receives her figure. No attacker is involved.
| Request | Header sent | Origin would render | Key used | Result under URL-only key |
|---|---|---|---|---|
Alice: /quote | X-Currency: USD | $100 | /quote | Response stored |
Bob: /quote | X-Currency: EUR | €92 | /quote | Served Alice's $100 |
Cache poisoning: one request writes for everyone
Make it reflected and the leak becomes poisoning. A support page prints the X-Client-Name header unescaped. An attacker sends a marker, the origin reflects it, the response is public and cacheable, and the next visitor receives attacker HTML from the edge. One request wrote an entry others read (Avoid web cache poisoning). The precondition is an application reflecting an input the key did not cover.
Cloudflare's guidance is blunt: do not rely on header values that are not in the key, do not reflect untrusted headers, and remember that GET bodies are cached but not keyed; bypass or use POST (Avoid web cache poisoning). The forwarding headers in the default key reduce one classic host-header family, not every header an application reads.
The table splits responsibility. On Free, Pro, and Business the answer is often bypass, because selective key controls are Enterprise-only.
| Input | In the default key? | Free, Pro, Business control | Enterprise control | Failure if left unkeyed |
|---|---|---|---|---|
| Query string | Yes, the full query | Ignore or sort query string; bypass by rule expression | Include or exclude specific parameters | Ignoring the query merges ?user=alice and ?user=bob into one entry |
| Cookie | No | Bypass on a cookie name with a rule expression | Include a cookie name and value in the key | Alice's page is stored and served to Bob; per-session keys destroy hit rate and single-file purge |
| Authorization | No | Send private or no-store; bypass the API path; Origin Cache Control is on by default | Bypass or origin no-store; keying on a bearer token is not authorization | A per-token JSON response is reused across tokens when it says public |
| Custom header | No | Cannot add it; bypass the route or stop reflecting it | Include the header in the key | Currency or tenant mismatch; a reflected header becomes stored XSS |
| Accept-Language with Vary | No, until Vary is configured | Enable the Cache Rules Vary setting and normalize the header | Same, plus a custom key if needed | One language is served to everyone, or worse, a locale-specific price |
| GET body | No, but the body is cached | Make GET idempotent, bypass, or reject bodies | Same; the body cannot be added to the key | An attacker's body changes the cached response for later readers |
| Normalized path | Key uses the normalized URL | Enable Normalize URLs to origin | Same | Two paths share one key while the origin routes them to different content |
Authorization is not a cache signal
The Authorization row deserves care. With Origin Cache Control on, the default on Free, Pro, and Business, an authorized request caches only with public, s-maxage, or must-revalidate. On Enterprise it is off by default, and the Authorization header alone does not prevent caching (Cache responses). The application must mark a per-token response private.
Figure 3 traces the poisoning path. It succeeds only when the header changes the body, the response is storable, the attacker can prime, and the victim maps to the same key.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
sequenceDiagram
autonumber
participant A as Attacker
participant E as Edge cache
participant O as Origin
participant V as Victim
A->>E: GET /support?q=refund
X-Client-Name: attacker-marker
E->>O: forward request, header not in key
O-->>E: 200 HTML reflects marker
Cache-Control: public, max-age=600
E->>E: store under /support?q=refund
E-->>A: poisoned response
V->>E: GET /support?q=refund
no attacker header
alt fresh entry exists
E-->>V: HIT with attacker-marker in HTML
else expired, purged, or not storable
E->>O: forward victim request
O-->>V: clean HTML
end
Those are the preconditions. Remove one and it fails: private removes storability, a different query removes key equality, a key including the header removes the gap. A WAF may inspect the attacker and still let a clean victim read the entry.
Attackers also choose when to prime. A response cached for 600 seconds gives an attacker a 600-second window in which every matching victim reads the poisoned entry. A short TTL reduces the window; it does not remove the bug. Purging is containment, not a fix, because the next request can refill the entry.
Normalization, Cookies, and Authorization
Normalization is where two systems disagree about "the same URL." Cloudflare always collapses adjacent slashes. Normalize incoming URLs runs before rules, WAF, Workers, and Access. Normalize URLs to origin controls what the origin receives and is off by default (URL normalization settings).
That gap is a surface. With incoming on and to-origin off, the edge can key /pricing and /%70ricing as one object while the origin sees two targets. If it routes them differently, one key holds two representations. Cloudflare recommends enabling Normalize URLs to origin with custom keys or device type to keep key and origin aligned and prevent poisoning (Cache keys). All plans.
Vary has the same trap. It is available on all plans, but it is off unless the rule defines it.
Vary normalize is lossy
The Vary setting is off if the vary object is omitted; a wildcard Vary always bypasses. When enabled, each header gets normalize, passthrough, or bypass (Vary). Normalize is lossy: it lowercases, sorts, drops quality values except q=0, strips region variants, and drops values outside an allowlist. Good for Accept-Language; dangerous when the exact value selects a tenant. For generic headers it only combines duplicate lines and trims whitespace; the origin header is not rewritten. Test the exact header the application reads.
Cookies are the identity channel the cache cannot see. The Cookie header is not in the default key, and a Set-Cookie response depends on plan and rule. With Origin Cache Control on and the default level, Cloudflare preserves the header and does not store; an eligible rule with no explicit edge TTL keeps it but still refuses storage, so every request misses; an explicit Edge TTL override strips it and stores. On Enterprise with Origin Cache Control off, the default may cache with the cookie stripped. The header is not portable.
Cookie is not a cache policy
The most consequential cookie mistake is treating Set-Cookie as a universal "do not cache" signal. Its protection depends on the plan and the rule: an explicit Edge TTL override strips it and stores the response, and Enterprise accounts with Origin Cache Control disabled can cache it by default. A personalized page needs private, no-store or an explicit bypass, not a hopeful cookie.
A Vary on Cookie is not a privacy switch. The setting must be enabled, and then it partitions per session: unbounded cardinality, a poor hit ratio, and purge keys the dashboard cannot reproduce. Bypass authenticated routes instead.
Authorization is plan-sensitive, and the edge cannot see token scope. If an API response differs by bearer token, send a private, no-store response or bypass the route.
Figure 4 shows the boundary and the assumption: the key includes what the edge selected; the origin may depend on what the key never saw.
The PayPal case is the canonical confusion. In 2017 Omer Gil showed that /myaccount/home/stylesheet.css returned the personalized account page because the origin treated the extra segment as the dynamic route while the cache treated .css as static. Reported exposure included names, account balance, and partial card data (Gil, 2017). No header was involved; the path was the unkeyed meaning.
Neither layer can do the other's job. Cloudflare builds the key, applies rules, honors Vary when configured, refuses private and no-store, applies plan-specific cookie behavior, and offers Cache Deception Armor. The application classifies responses, sends correct cache headers, never reflects unkeyed input, authenticates before rendering, normalizes both layers the same way, and tests two principals.
A Small Matrix That Exposes Cache Confusion
A small matrix finds the dangerous cell. Ask: does the key cover every varying input, does the representation vary by principal, and is it storable?
Four cells: key covers and storable is correct partitioning, at cardinality cost; key covers and not storable is safe but idle; key misses and not storable is safe by refusal, at origin cost; key misses and storable is leak or poison. If the representation is invariant, an unkeyed input is harmless but fragile.
Cache confusion: believing the wrong cell
Cache confusion is believing one cell while operating in another. Vary on Cookie assumed to partition, but the Vary setting is off. A private response assumed to protect, but a later Edge TTL override stores it. A .jpg path assumed static, but the origin aliases it to a personalized route and the cache stores HTML.
Deception has four concrete preconditions. The origin aliases a dynamic page under a static path; the cache stores by extension or rule; the victim is authenticated and lured; the attacker can fetch the same URL. Web cache deception uses exactly that shape. Cache Deception Armor breaks the second condition by comparing the extension with Content-Type and refusing a mismatch (Cache Deception Armor). It is available on all plans but must be enabled in a Cache Rule; it depends on Origin Cache Control, has exceptions such as application/octet-stream, and can be overridden by an origin cache header or Edge TTL. It is a mitigation, not proof that the origin's routing is correct.
Over-keying spends hit ratio, origin capacity, and purge simplicity; attacker-controlled headers add arbitrary variants, and per-session keys break single-file purge. Under-keying spends privacy and integrity. Bypass spends origin capacity but is honest. Figure 5 shows the repair.
The matrix is a diagnostic, not a proof. It tells you where to look; it does not tell you which input the origin actually reads. That requires a request trace, a body diff, and a controlled prime-and-probe. A team that fills the matrix from memory has documented its beliefs, not its system.
Read the status before the body. CF-Cache-Status: DYNAMIC means not eligible at request time; BYPASS means eligible but the response was not cacheable. Age appears on HIT, STALE, and UPDATING, not on DYNAMIC or BYPASS, though an origin Age is proxied. Cache-header precedence runs from the Cloudflare-specific header down to CDN-Cache-Control and then Cache-Control (Cache responses). A body-only test misses the status; a status-only test misses whether the body was personalized.
Analyze a Local Cache-Policy Fixture
A local fixture is a program you control that takes a request, computes a key, renders a representation, and decides whether to store it. It is not a Cloudflare emulator; it is a policy oracle. It makes your assumptions executable and lets you enumerate the matrix before touching a zone. For Enterprise-only controls, the fixture is the honest substitute and must be labeled as a model, not hosted validation.
Make it adversarial: one input in the key, one not; a cache that stores any 200 with public; two principals with distinct markers. Run the same sequence with the URL-only policy and the repaired policy, then diff the results.
Analyze a Local Cache-Policy Fixture
Execution status: design-only. Not executed. Planning baseline 2026-11-02; documentation re-checked 2026-11-05. No local or hosted run occurred, and no measured result is claimed. Expected observations are acceptance criteria, not findings.
Prerequisites and plan requirements. Node.js 22 LTS or current LTS, a terminal, and a temporary directory. The local part needs no Cloudflare account. The optional confirmation needs a domain on Cloudflare, one proxied DNS record, and an origin you control; the Free plan suffices. Enterprise-only custom header or cookie keys cannot be exercised on Free; model them locally. Use invented principals only, and never prime or probe a domain you do not own.
Minimal setup. Create three files: server.mjs (Node's built-in http module only), policy.json, and run.mjs. The server exposes:
GET /assets/app.js: fixed JavaScript,public, max-age=86400.GET /pricing: readsAccept-Language;price=100foren,price=92forfr;public, max-age=300; noVary.GET /account: readssession; returns that name plus a CSRF token;private, no-store.GET /quote: readsX-Currency;total=100ortotal=92;public, max-age=600.GET /support: reflectsX-Client-Name;public, max-age=600.GET /api/me: requiresAuthorization: Bearer aliceorbob; returns that principal's JSON withpublic, max-age=600, modeling the unsafe Enterprise case.GET /newsandGET /news/anything.jpg: both return the same public HTML (public, max-age=300); the.jpgpath sendsContent-Type: text/html, the deception alias.
Run the matrix in two passes. Every probe compares what Alice primed with what Bob receives.
| Step | URL-only policy | Repaired policy | What it proves |
|---|---|---|---|
/quote: prime USD, probe EUR | Bob gets Alice's $100 | Bob gets €92 | An unkeyed header leaks content |
/support: prime a marker, probe clean | Victim HTML contains the marker | Bypass or clean HTML | A reflected header poisons the entry |
/pricing: prime en, probe fr | French visitor gets the English price | Key includes the normalized language | Locale is content |
/account: Alice, then Bob | Origin private forces a bypass | The same bypass | Identity never shares an entry |
/api/me: Alice, then Bob | Bob may receive Alice's JSON | Bypass or a per-token response | Authorization is not a key |
/news/anything.jpg | Stored text/html under an image URL | Bypass or 404 | The deception alias is closed |
| Re-run the first six after repair | Three or more cross-principal results | Zero cross-principal results | The policy is internally consistent |
Optional hosted confirmation. Deploy the fixture, add a Cache Rule making the support route eligible with a 60-second Edge TTL, prime with the marker, probe without it, and expect a hit, the marker in the body, and a rising age. The probe can use curl -sD -. Delete the rule and purge immediately.
Expected observations. The URL-only run should show at least three cross-principal results: currency, support marker, and locale. The repaired run should show zero. The public asset should move from a miss to a hit with age in both runs; if it does not, the fixture stores nothing and the comparison is meaningless.
Failure checks. All routes bypass proves nothing; an account hit, an age on a personalized response, or a missing set-cookie each point to a different layer. Identical body hashes across principals mean the renderer ignored identity or the key is shared, and a dynamic status on the support route after the rule means the rule did not match.
Cost dimensions. The local run is free: roughly 30 minutes to build and 10 to run. The optional hosted confirmation uses a domain and origin you already have; request volume is negligible and the Free plan suffices. Enterprise custom keys require an Enterprise plan and are design-only here.
Cleanup. Stop the server, delete the directory and both results files, delete the test rule, purge the support and quote routes, remove the test DNS record or origin, and discard the invented sessions and tokens. Confirm the account route bypasses and the public asset still works.
The policy file is the thing under test. Each route maps to a key and a TTL, optionally with extra headers or a bypass, and the runner prints one row per request.
The fixture cannot prove Cloudflare's behavior; it proves your policy has no internal contradiction. The optional hosted step is the only part that observes the real edge, and it is deliberately narrow: one route, one rule, one marker, one purge.
Prove the Correct Policy Separates Two Principals
Planned exercise: execution not yet performed. Documentation was verified on 2026-11-05 against the pages below. No local or hosted run occurred, no product version was tested, and no hit ratio, latency, or leak rate is measured.
Pass evidence. For every protected route, send the same request as Alice and Bob and store the full headers plus a body hash. A release candidate passes when:
- Protected routes return DYNAMIC or BYPASS, carry no Cloudflare age, preserve the set-cookie header, and contain only their own principal's marker.
- Public routes are byte-identical across principals, move from a miss to a hit, and carry an increasing age.
- Key coverage shows every body-changing input in the key, from the Rules simulator or trace, or the route bypasses.
- Deception and API close the alias: the image-extension path bypasses or returns 404, never cached HTML, and the per-token API response is never served from a shared entry.
Fail evidence. Any cross-principal marker, any hit on a personalized route, any age on a personalized response, a missing set-cookie, cached HTML under an image extension, or an authorized JSON response shared across tokens. A pass that occurred only because the origin sent a private header is incomplete: it shows the origin header works, not that the rule or key is correct.
Evidence to keep. One row per request: timestamp, route, principal, key from the simulator or trace, cache status, age, cookie presence, body hash, marker, rule ids, and the response cache header. The body alone is not evidence; the status alone is not evidence. The pair is.
Treat the result as a release gate, not a score. Block on any cross-principal marker, any hit on a personalized route, or any shared authorized response. Warn when a public route stops hitting or when age disappears without a rule change. Observe hit ratio and origin load. Re-run the matrix when a Cache Rule, a Vary setting, an origin header, an authentication flow, or a URL normalization setting changes, because each one can move a route from the safe cell to the leak cell.
Self-check, with explanations.
Why does Vary: Cookie fail to protect a shared page? The Vary setting is off unless the matching Cache Rule defines it, so the cookie may never enter the key. Even when on, it creates one entry per cookie value: unbounded cardinality, a poor hit ratio, and purge keys the dashboard cannot reproduce. Bypass the authenticated route instead.
Why is CF-Cache-Status: DYNAMIC not proof of safety? It means the request was not eligible at request time. That may be a deliberate bypass, a default, or a rule that will be edited later. It does not prove the response is unstorable or that the key excludes the session. Check the rule, the trace, and the response headers, and repeat after any rule change.
Why can two different paths share one cache entry? The key uses the URL Cloudflare normalized, while the origin may receive the original URL when Normalize URLs to origin is off. Baseline normalization, encoded characters, duplicate slashes, and custom keys can all collapse distinct targets. If the origin routes them differently, one key holds two representations; enable normalization to origin and test the exact paths.
Unresolved limitations. The fixture and hosted check cover the edge cache only; browser caches, service workers, origin proxies, Worker caches, and Tiered Cache add their own storage and lifetime decisions. CF-Cache-Status is a signal, not a key dump; the key is visible in the Rules simulator or trace, and even there it reflects the configuration at request time. Cache Deception Armor depends on Origin Cache Control and can be overridden by an origin cache header or an Edge TTL rule. Enterprise-only custom keys, plan-specific set-cookie behavior, and authorization behavior were not executed. Vary normalization is lossy and may change. Prices, limits, and entitlements are dated to 2026-11-05 and must be re-checked before publication. Finally, cache poisoning and web cache deception are attacks on systems you own or are authorized to test; the experiment is limited to invented data on a controlled hostname.
References (verified 2026-11-05):
- Cloudflare Cache: https://developers.cloudflare.com/cache/
- Cache keys: https://developers.cloudflare.com/cache/how-to/cache-keys/
- Cache Rules: https://developers.cloudflare.com/cache/how-to/cache-rules/
- Cache Rules settings, including Vary: https://developers.cloudflare.com/cache/how-to/cache-rules/settings/
- Vary: https://developers.cloudflare.com/cache/concepts/vary/
- Cache responses and
CF-Cache-Status: https://developers.cloudflare.com/cache/concepts/cache-responses/ - Set-Cookie and cache behavior: https://developers.cloudflare.com/cache/concepts/cache-behavior/
- Origin Cache Control: https://developers.cloudflare.com/cache/concepts/cache-control/
- Avoid web cache poisoning: https://developers.cloudflare.com/cache/cache-security/avoid-web-poisoning/
- Cache Deception Armor: https://developers.cloudflare.com/cache/cache-security/cache-deception-armor/
- URL normalization: https://developers.cloudflare.com/rules/normalization/
- URL normalization settings: https://developers.cloudflare.com/rules/normalization/settings/
- Rules simulator: https://developers.cloudflare.com/rules/simulator/
- RFC 9111, HTTP caching: https://www.rfc-editor.org/rfc/rfc9111.html
- OWASP, Cache Poisoning: https://owasp.org/www-community/attacks/Cache_Poisoning
- PortSwigger, Web Cache Deception: https://portswigger.net/web-security/web-cache-deception
- Omer Gil, Web Cache Deception Attack (2017): https://omergil.blogspot.com/2017/02/web-cache-deception-attack.html