Three cookie facts explain most Cloudflare surprises. First: request cookies pass through to your origin untouched, but they are not part of the cache key — a cached page is served to everyone regardless of who is logged in. Second: a response carrying Set-Cookie is normally not cached, but if a rule forces an Edge TTL, Cloudflare caches it and strips the Set-Cookie header — which is how forced caching breaks logins. Third: cookies named __cf_bm, cf_clearance, or __cflb were set by Cloudflare, not your application, and deleting or blocking them creates problems you will misdiagnose. This article covers all three, plus the cookie-based bypass recipe every session-bearing site needs.
What’s happening
On the request path, Cloudflare forwards the Cookie header to the origin as-is. What it does not do is vary the cache by it: two visitors with different session cookies hitting a cached URL get the same cached bytes. Including a cookie in the cache key is an Enterprise custom-cache-key feature — on Free, Pro, and Business the only safe pattern for personalized HTML is to not cache it, which is what the bypass recipe below does.
On the response path, Set-Cookie acts as a caching signal. With default behaviour, a response that sets a cookie is treated as personal and not stored. The sharp edge appears when a Cache Rule (or legacy “Cache Everything” Page Rule) overrides the Edge TTL: Cloudflare then does cache the response and removes the Set-Cookie header from the stored copy. The next user receives the page without the cookie that was supposed to establish their session — hence login loops and vanishing carts on sites that forced HTML caching too broadly.
Separately, Cloudflare sets its own cookies at the edge. The ones you will actually meet: __cf_bm (bot detection, roughly 30-minute lifetime, appears when bot features are active on the zone), cf_clearance (proof a visitor passed a challenge, scoped to the zone), __cflb (session affinity for Cloudflare Load Balancing), __cfruid (challenge and rate-limiting plumbing), and __cfwaitingroom (Waiting Room position). They are documented under Cloudflare fundamentals; your privacy policy should list them, and your code should ignore them.
What to check first
- Is HTML being force-cached anywhere? Rules » Cache Rules — look for Edge TTL overrides matching page paths.
- Do logged-in users report seeing someone else’s content, or losing sessions? The first is cookie-blind caching; the second is
Set-Cookiestripping. - Are you seeing “mystery cookies” in the browser? Check the name against the Cloudflare list before blaming a plugin.
How to verify
# Does the login/session path set a cookie, and is it being cached?
curl -sI "https://example.com/my-account/" \
| grep -iE "set-cookie|cf-cache-status|cf-ray|cache-control|vary"
# Compare anonymous vs cookie-bearing requests on a cached page
curl -sI "https://example.com/"
curl -sI "https://example.com/" -H "Cookie: wordpress_logged_in_abc=test"
# Both HIT with identical content = cookies are not splitting the cache (expected)
# Confirm the origin actually sends Set-Cookie (rules out edge stripping)
curl -sI --resolve example.com:443:<ORIGIN_IP> "https://example.com/my-account/" \
| grep -i "set-cookie"
# Watch who reaches the origin once bypass is in place
tail -f /var/log/nginx/access.log | grep "my-account"
A response with cf-cache-status: HIT and no set-cookie through the proxy, but with set-cookie in the direct --resolve test, is the stripped-cookie signature.
The fix
- Bypass cache when a session cookie is present. Create a Cache Rule with the expression
(http.cookie contains "wordpress_logged_in") or (http.cookie contains "PHPSESSID")— substitute your framework’s session cookie names — and the action Bypass cache. This is the modern replacement for the old Business-plan “Bypass Cache on Cookie” Page Rule; Cache Rules made cookie matching available on all plans. - Never force Edge TTL on paths that set cookies. Login, checkout, account, and cart URLs should match a Bypass rule that sits above any broad caching rule in the rule order. First matching rule wins the argument.
- Cache aggressively for anonymous traffic only. The pairing that works: rule 1 bypasses on session cookie, rule 2 caches HTML for everyone else. Anonymous visitors get edge speed; logged-in users get their own pages from the origin.
- Strip irrelevant cookies from static assets at the origin. Analytics cookies on
.cssand.woff2requests do not prevent Cloudflare from caching those (static extensions cache by default), but serving cookie-free asset domains keeps request headers small and your logs cleaner. Optional, not urgent. - Leave Cloudflare’s cookies alone. Do not delete
__cf_bmin application code, do not block it in a consent tool’s “strictly necessary” tier, and do not add it to session-validation logic. If a challenge loop appears, the fix is WAF tuning, not cookie surgery.
When this fix is wrong
If the requirement is “cache personalized pages per user,” bypass is not the answer and neither is anything on a non-Enterprise plan — per-cookie cache keys are Enterprise territory, and even there they multiply your cache into near-uselessness. Restructure instead: cache the anonymous shell, fetch personal fragments from an uncached API. And if sessions break identically with Cloudflare paused, your problem is the application’s cookie settings (Secure, SameSite, domain scope), not the edge.
Common mistakes
- “Cache Everything” plus Edge TTL on the whole zone. The classic self-inflicted outage: every
Set-Cookiestripped, logins loop, carts empty. Scope caching rules to what is genuinely shared. - Assuming
Vary: Cookiesplits the Cloudflare cache. It does not. Vary is not part of the cache key here (apart fromAccept-Encoding). - Matching the wrong cookie name in the bypass rule. WooCommerce, Laravel, Django, and Rails all name session cookies differently, and some prefix per-site hashes. Check a real browser’s cookie jar, then write the rule with
containson the stable part of the name. - Blaming
__cf_bmfor user-facing bugs. It is a bot-scoring cookie with a short lifetime. It does not log users out and it does not carry your session.
Prevention
Keep a one-line inventory of which cookie names mean “this visitor is stateful,” wire them into the bypass rule, and re-test login and checkout through the proxy after any caching change — two curls and a browser session, five minutes. When you change caching rules, purge and re-verify rather than waiting for support tickets; cache purge strategies and the cache rules guide cover the mechanics. If “is it Cloudflare or is it us” keeps eating your evenings, that triage is literally the job of 24/7 Monitoring & Response — book a monitoring and response review.