A shop's Cloudflare Cache Rule makes the whole hostname Eligible for cache with an Edge TTL ignoring Cache-Control; customers see others' account pages and sign-ins fail. Why, and what fixes it?
answer
- the expression matches too much
- override ignores private
- Set-Cookie stripped before storing
- no cookie in the default key
- a later bypass rule wins
basics
~20 sThe rule also matched account and login pages; its override Edge TTL ignored private, so Cloudflare stripped Set-Cookie and shared one customer's page. Narrow it, add a later Bypass cache rule on personal paths and the session cookie, then purge.
solid answer
~50 sAn expression like `http.host eq "shop.example.com"` matches `/account`, `/cart` and `/login` too. **Eligible for cache** made those HTML responses cache candidates, and the Edge TTL **Ignore cache-control header and use this TTL** (`override_origin`) discarded the origin's `private` and `no-store`. With an explicit Edge TTL, Cloudflare removes `Set-Cookie` and stores the response, so the first signed-in page cached in a data center is served to later visitors (the default key has no cookie in it), and browsers never receive the session cookie, which breaks sign-in. Confirm with `cf-cache-status: HIT` and a missing `Set-Cookie` on `/account`. Fix it by limiting the eligible rule to catalogue paths and static files, adding a **Bypass cache** rule after it for personal paths and requests carrying the session cookie (the last matching rule wins), keeping `respect_origin` on HTML, and purging the leaked URLs.
code
plaintext · 1 line(http.host eq "shop.example.com" and (starts_with(http.request.uri.path, "/products/") or starts_with(http.request.uri.path, "/c/") or http.request.uri.path.extension in {"css" "js" "png" "jpg" "webp" "woff2"}))go deeper
Recall that a Cache Rule matching a whole hostname also matches account and login pages, and that personal pages must never be cached.
Explain how override_origin ignores private and no-store, and why Cloudflare strips Set-Cookie when an explicit Edge TTL caches a response.
Diagnose from HIT plus a missing Set-Cookie, then fix with a narrowed eligible rule, a later bypass on paths and the session cookie, respect_origin on HTML, and a purge.
Turn the incident into policy: allowlisted eligible paths, a mandatory final bypass rule, and review of any override_origin before it ships.
## What the rule actually did The rule `(http.host eq "shop.example.com")`, set to **Eligible for cache** with the Edge TTL option **Ignore cache-control header and use this TTL** (`override_origin`), matches every request to the shop: product pages, but also `/account`, `/cart`, `/checkout` and `/login`. Three behaviours combine: 1. **Eligible for cache** makes every matching response a cache candidate, HTML included. 2. **`override_origin`** ignores the origin's `Cache-Control` entirely, so `private` and `no-store` on the account page no longer protect it. 3. When a response carries **`Set-Cookie`** and an explicit Edge TTL applies (override or Status Code TTL), Cloudflare **removes the `Set-Cookie` header and stores the response**. The default cache key holds no cookies, so every visitor's request for `/account` in a data center maps to one entry. Whichever signed-in customer's page was stored first is served to the next visitors until the TTL runs out, and the pattern differs between locations because each one fills its own copy. Because `Set-Cookie` was stripped, the session or CSRF cookie the login page should hand out never reaches the browser, so sign-ins bounce back to the login form or fail validation. ## Confirming it - Request `/account` and `/login` with `curl -sI`. A `cf-cache-status` of `HIT` or `EXPIRED` together with the absence of a `Set-Cookie` header the origin normally sends is the signature. - An `Age` header on those responses shows they came out of cache. - Sign in as two different test customers and load `/account` from the same location; if the second sees the first one's name or orders, the entry is shared. - Cloudflare Trace for the URL lists which Cache Rules matched and the settings they applied. - Form posts are not what leaked: Cloudflare caches only `GET` and `HEAD`, so it is the page fetch that was stored. ## Fixing it 1. **Narrow the eligible rule** to anonymous content: product and category paths and static extensions, never the bare hostname. 2. **Add a Bypass cache rule after it** for personal paths and signed-in requests: `/account`, `/cart`, `/checkout`, `/login`, the API, and any request carrying the session or cart cookie. Cache Rules stack, and when two matching rules set the same setting the **last matching rule wins**, so this later bypass overrides the earlier eligibility for those requests. 3. **Keep `respect_origin` on HTML**, so the origin's `private`, `no-store` and `Set-Cookie` keep personal responses out even if a path slips through; keep `override_origin` for files that can never be personal. 4. **Have the origin mark personal pages** `Cache-Control: private` or `no-store`, as a second layer that does not depend on the rule list. 5. **Purge the affected URLs or hostname** after the change (the purge material covers the methods). The bad copies stay stored until they expire, and any request the new rules still treat as eligible could be served from them. 6. **Verify**: `/account` now goes to the origin with `Set-Cookie` intact, while product pages still return `HIT`. ## Choosing the cookie condition | Condition | Plans | What to know | |---|---|---| | `http.cookie contains "shop_session="` | All | A substring test on the whole `Cookie` header; it can also match a similarly named cookie, which errs on the safe side for a bypass | | The `http.request.cookies` map field | Pro and above | Tests a cookie by its exact name instead of a substring | Bypassing on the cookie also sends signed-in customers' product page views to the origin. That is the intended trade: a page that may show a name, a basket count or member prices is not anonymous. ## Why the tempting alternatives fail - **Keying the cache on the session cookie** (a Cookie part of an Enterprise custom key) creates one entry per user: the hit rate collapses while personal pages still sit at the edge. - **Cache Deception Armor** compares a URL's extension with the response `Content-Type`. `/account` has no misleading extension, so it would not intervene, and an Edge TTL override may defeat it anyway. - **Moving the Bypass rule to the top of the list** does not help: the broad eligible rule, evaluated later, would win the conflict. - **Purging alone** clears the leaked copies, but the next signed-in visit refills them while the broad rule stands. - **Shortening the Edge TTL** only narrows the window; every refill still stores whichever customer arrived first.
- Would switching the broad rule's Edge TTL to respect_origin alone have been enough?Only while every personal route sends `private` or `no-store`, or sets a cookie. Under `respect_origin` Cloudflare honours those, so a correctly marked account page is not stored. One route that forgets the header, or sends `public, max-age`, would be cached and shared again. The path and cookie bypass rule is the control that does not depend on every route being right.
- Why did different customers see different leaked accounts, and only in some regions?Each Cloudflare data center fills its own copy, so the stored page is whichever signed-in customer's request reached that location first. Visitors served elsewhere saw another customer's page, or a fresh one. The picture also shifts each time the entry expires and the next request refills it, which is why such leaks look random from the support desk.
- The Ignore cache-control header Edge TTL still honours Cache-Control: private on account pages.
- Cloudflare never caches a response carrying Set-Cookie, whatever a Cache Rule says.
- Putting the Bypass cache rule first in the list makes it win over the broad eligible rule.
- The default cache key already separates users by their session cookie.
- Purging the edge also clears the copies visitors' browsers already hold.