skip to content

After a consent plugin made a Cloudflare Pro site's origin send Set-Cookie on every response, its stylesheets and images went from HIT to BYPASS; why, and how do you fix it safely?

level: seniorimportance: should knowfreq 45%

answer

  1. decided after the origin answers
  2. a cookie is per visitor
  3. Origin Cache Control on below Enterprise
  4. name the header to drop

basics

~20 s

Without a Cache Rule override, a Free, Pro or Business zone does not store a cacheable response carrying Set-Cookie: Cloudflare forwards the cookie and reports BYPASS. Stop setting cookies on static responses, or send private="Set-Cookie" so Cloudflare caches without it.

solid answer

~40 s

The asset requests are still eligible, but the response now carries `Set-Cookie`. With **Origin Cache Control** on, which it always is on Free, Pro and Business, Cloudflare does not cache such a response, passes the cookie to the visitor and reports `BYPASS`; only an Enterprise zone with Origin Cache Control off would strip the cookie and cache. Confirm it by comparing the origin's headers for `Set-Cookie`, `no-store`, `private`, `Vary: *` and size. The cleanest fix is at the origin: keep the consent code off static paths. Alternatively the origin sends `Cache-Control: public, max-age=86400, private="Set-Cookie"`, and Cloudflare stores the file without that header. Avoid a site-wide Cache Rule with an Edge TTL override: it would cache HTML, strip its cookies and break sign-in.

code

http · 7 lines
http
HTTP/2 200
content-type: text/css
cache-control: public, max-age=86400
set-cookie: consent_id=8c1e5d0a; Path=/; Max-Age=31536000; SameSite=Lax
cf-cache-status: BYPASS
server: cloudflare
cf-ray: 8d2f71e04a9c3b22-AMS

go deeper

for a junior

Recall that a cookie on a response can stop Cloudflare from caching it, and that BYPASS is the label for that refusal.

for a middle

Explain why the plan matters: Origin Cache Control is always on below Enterprise, so Set-Cookie blocks storage instead of being stripped.

for a senior

Rule out the other BYPASS triggers before blaming the cookie, fix it at the origin or with private="Set-Cookie", and verify both HIT on assets and intact cookies on pages.

for a principal

Turn it into a standing rule: no cookies on static responses, and a cache-status check in the release checklist for any plugin or framework upgrade.

## The symptom A news site sits behind Cloudflare on the Pro plan. Its article pages have always shown `cf-cache-status: DYNAMIC`, which is expected: HTML is not on Cloudflare's default list of cached extensions. Its stylesheets, scripts, photos and fonts used to show `HIT`. After a consent plugin was installed on the origin, every response, assets included, carries a `Set-Cookie` header, and the assets now show `BYPASS` on every request. Origin load and bandwidth climb, and pages slow down. ## Why the assets stopped caching The asset requests are still **eligible**: their extensions are on the default list, so the request-time decision is unchanged. The change happens at **response time**. Cloudflare's rule for a cacheable request whose origin response contains `Set-Cookie`, under the default cache level, depends on **Origin Cache Control**: | Configuration | What the edge does with a `Set-Cookie` response | |---|---| | Origin Cache Control on (always, on Free, Pro and Business) | Does not cache it, passes `Set-Cookie` to the visitor, reports `BYPASS` | | Origin Cache Control off (an Enterprise option) | Removes `Set-Cookie` and caches the file | The behaviour is protective. A cookie is per visitor; storing a response with its cookie would hand one visitor's cookie to everyone, and silently removing it can break whatever the cookie was for. So on this Pro zone the safe choice wins and the file is not stored. The article pages are unaffected in a different way: an ineligible request always keeps its `Set-Cookie`, and stays `DYNAMIC`. ## Confirm before fixing Do not assume the cookie is the cause; `BYPASS` has several response-time triggers. Fetch an asset from the origin directly and through Cloudflare, and check: - `Set-Cookie` present on the asset response (the suspected cause); - `Cache-Control` with `no-store` or bare `private`; - `Vary: *`, which always bypasses; - `CDN-Cache-Control` or `Cloudflare-CDN-Cache-Control` with `no-store` (the second is never forwarded to clients, so read it at the origin); - a body over the plan's cacheable size limit (512 MB on Pro); - an `Authorization` request header without `public`, `s-maxage` or `must-revalidate` in the response. ## Fixes, from best to last resort 1. **Stop setting cookies on static responses.** Scope the consent plugin, or the middleware that runs it, to application routes, or serve assets from a path or hostname the cookie code never touches. Nothing about the cache needs to change, and no visitor's cookie is put at risk. 2. **Let the origin name the header to drop.** Returning `Cache-Control: public, max-age=86400, private="Set-Cookie"` (or `no-cache="Set-Cookie"`) tells Cloudflare to store the response without that header. The file becomes cacheable again, and only the named header is left out of the stored copy. 3. **Strip the cookie at Cloudflare for static paths only.** A Cache Response Rule can strip `Set-Cookie` before the cache decision; scoping it tightly to asset paths is essential, and the rule itself is covered with Cache Rules. What not to do: make the whole site eligible with a broad Cache Rule and an Edge TTL that ignores origin headers. Cloudflare would then cache article and account pages and remove their `Set-Cookie`, and sign-in and consent flows break because the browser never receives the cookie. ## Why the plan changes the answer The same origin behaves differently on an Enterprise zone where Origin Cache Control has been turned off: under the default cache level, Cloudflare removes `Set-Cookie` from the asset response and caches the file, so the assets keep showing `HIT` and visitors silently never receive the cookie on those requests. Even there, a Cache Rule that marks the path eligible without an explicit Edge TTL overrides this and returns `BYPASS`. Knowing which configuration a zone runs is part of the diagnosis, because "Set-Cookie blocks caching" is true on Free, Pro and Business and only conditionally true on Enterprise. ## Verifying the fix 1. Request an asset twice from the same location (same `cf-ray` suffix): the first response may be `MISS`, the second must be `HIT` with an `Age` header and no `Set-Cookie`. 2. Request an article page: it should still be `DYNAMIC` and still carry `Set-Cookie`, proving visitors' cookies flow as before. 3. Watch the cache-status mix in analytics: `BYPASS` should fall back to its pre-plugin level and the hit ratio should recover. ## The general lesson On Free, Pro and Business zones, a `Set-Cookie` on an otherwise cacheable response is a cache kill switch, and it is often added by code nobody associated with caching. Treating "no cookies on static responses" as an origin rule, and checking `cf-cache-status` after any plugin or framework upgrade, keeps it from happening again.

  • Why do the same Cloudflare news site's article pages keep showing DYNAMIC rather than BYPASS after the plugin change?
    Article pages are HTML on extensionless paths, so they are ineligible before any response arrives, and the request is labelled `DYNAMIC`. For ineligible requests Cloudflare always preserves `Set-Cookie`, so consent and session cookies reach visitors exactly as before. `BYPASS` only appears on requests that were eligible, like the assets.
  • After scoping the plugin, how do you find any Cloudflare-proxied asset paths that still carry the cookie?
    Request a sample of each asset type through the proxy and check for `set-cookie` and `cf-cache-status`. Then, in Cache Analytics, filter by **Cache status** `BYPASS` and by **Path** or **Content type**: the top URLs that remain are the responses still refused, and fetching one from the origin shows whether `Set-Cookie` or another header is the reason.
  • How would the same responses behave on an Enterprise Cloudflare zone with Origin Cache Control turned off?
    Under the default cache level, Cloudflare would remove `Set-Cookie` from the asset response and cache the file, so assets would keep showing `HIT`. The cookie would silently never reach visitors on those requests. A Cache Rule marking the path eligible without an explicit Edge TTL would override that and return `BYPASS` instead.

  • Cloudflare caches the response and replays the same Set-Cookie to every visitor.
  • BYPASS means the asset's extension is not on the default list.
  • A site-wide Cache Rule with an Edge TTL override is the safe fix.
  • Set-Cookie behaves the same on every plan.
  • Purging the cache will bring the HIT status back.