If anonymous visitors are seeing someone else’s name, account menu, or cart count, a Cache Everything Page Rule — or a Cache Rule that makes HTML eligible for cache — stored a page the origin rendered for a logged-in user. Cloudflare keys its cache on the URL, not on who asked, so the first response to land in the cache is what everyone gets until it expires. The immediate fix is a purge; the real fix is a bypass rule on session cookies that wins over the caching rule.
What’s happening
A request crosses three cache layers: the visitor’s browser cache, Cloudflare’s edge cache, and whatever caches sit at the origin (plugin page cache, Varnish, object cache). By default Cloudflare only caches URLs ending in static extensions — CSS, JS, images, fonts — and leaves HTML alone. That default exists precisely because HTML is where personalization lives.
Cache Everything removes the guardrail. The edge cache key is host + path + query string; there is nothing about the requester in it. If the first request for /shop/ after a purge comes from a logged-in customer, the origin renders their page — name in the header, cart badge, account links — and the edge stores that body. Every visitor afterward gets the customer’s page until the TTL runs out.
Two details make this worse than expected. Cloudflare normally refuses to cache a response carrying Set-Cookie — but an Edge TTL override (“Ignore cache-control header and use this TTL”, or the legacy Edge Cache TTL page-rule setting) caches the response anyway and strips the Set-Cookie header. And Cloudflare does not use Vary: Cookie in the cache key, so the origin cannot segment cached copies per user that way.
What to check first
- The rules list. Caching → Cache Rules, plus legacy Rules → Page Rules. Look for Cache Everything or “Eligible for cache” matching HTML paths with no cookie condition anywhere.
- Edge TTL mode. Any rule set to ignore origin
Cache-Controlis what allowsSet-Cookieandprivateresponses into the cache. - The site’s session cookies.
wordpress_logged_in_*,wp_woocommerce_session_*,PHPSESSID,laravel_session, or a custom SSO cookie. - Origin headers on personalized pages.
Cache-Control: privateorno-storeshould be present — it is your safety net whenever rules honour it.
How to verify
Fetch a personalized-capable page anonymously and read the cache headers:
curl -sI https://example.com/shop/ | grep -iE '^(cf-cache-status|age|cache-control|set-cookie)'
cf-cache-status: HIT with a non-zero age on a page that renders differently for logged-in users is the alarm. Confirm what is stored by forcing a fresh copy with a cache-busting query and comparing bodies:
curl -s https://example.com/shop/ | grep -oE 'account-menu|logged-in|cart-count' | sort | uniq -c
curl -s "https://example.com/shop/?cachebust=$(date +%s)" | grep -oE 'account-menu|logged-in|cart-count' | sort | uniq -c
If the cached copy contains logged-in markup and the fresh copy does not, you are serving a private render. To see what the origin itself sends without Cloudflare in the path, pin the hostname to the origin IP:
curl -sI https://example.com/shop/ --resolve example.com:443:203.0.113.10 | grep -iE '^(cache-control|set-cookie)'
The fix
-
Purge first, investigate second. Caching → Configuration → Purge Everything. Cached logged-in pages can contain names, addresses, and order history — treat it as an incident, not a tuning task.
-
Add a bypass rule keyed on session cookies. Create a Cache Rule with action “Bypass cache” and an expression like the one below. In Cache Rules, when several rules match, later rules override earlier ones — place the bypass rule after the HTML-caching rule in the list so it wins.
(http.cookie contains "wordpress_logged_in") or (http.cookie contains "wp_woocommerce_session") or (http.cookie contains "PHPSESSID") -
Bypass the always-personal paths outright.
/cart,/checkout,/my-account,/wp-admin,wp-login.php, and any API endpoints. Cookie matching covers most cases; path bypass covers guest checkouts and edge cases where the cookie is not set yet. -
Stop overriding origin headers blindly. Set Edge TTL to “Use cache-control header if present” wherever possible, so
privateandno-storefrom the origin keep doing their job. -
Fix the origin. Personalized responses should send
Cache-Control: private, no-cache, no-store— WordPress does this for logged-in users by default; custom apps often forget. -
Re-test the full matrix. Anonymous request, logged-in request, then anonymous again — confirm the third request never shows the second request’s content and reads
BYPASSwhere cookies are present.
Plan note: this recipe needs only two Cache Rules, well inside the quantity limits (10 on Free, 25 on Pro, 50 on Business, 125 on Enterprise).
When this fix is wrong
If personalization is done client-side — JavaScript reads a cookie after load and fills in the header — then the cached HTML is identical for everyone and there is no leak; adding a cookie bypass would only destroy your hit rate. If the stale personalized page comes back even with Cloudflare paused, the leak is in an origin cache (LiteSpeed, Varnish, a WordPress page-cache plugin caching logged-in renders) and no edge rule will fix it. And if each user has their own URL (/user/123/), it is not a cross-user leak — but private data is still cached publicly, so bypass those paths anyway.
Common mistakes
- Counting on
Vary: Cookie— Cloudflare does not key the cache on it. - Assuming
Set-Cookieresponses are safe when an Edge TTL override is stripping the header and caching them. - Testing only while logged in, where everything looks personalized and correct.
- Bypassing
/wp-admin/but not the front-end pages where thewordpress_logged_incookie changes the render. - Purging before the bypass rule is deployed, so the very next logged-in visitor re-poisons the cache.
Prevention
Treat HTML caching as an allowlist, never a default: cache the pages you have proven anonymous, bypass everything else. Keep the session-cookie list documented and reused across zones. Test the anonymous/logged-in/anonymous sequence after every rules change, and review which paths return HIT in cache analytics monthly. The background on TTL and cache-key mechanics is in Cache Rules cacheability, and the WordPress-specific rule set is in which Cloudflare Cache Rules pay off for WordPress; the official reference is the Cloudflare cache documentation.
An HTML cache that leaks one session does more damage than an HTML cache ever saves. Cache layers that fight each other cost real revenue — Stack Harbor tunes the whole stack, edge to origin, under Managed Cloud Ops; book an infrastructure review.