Skip to content

bug: perf/bad-caching reports no ETag when the server sends a weak ETag (Cloudflare, zstd) #600

Closed

Description

@doradorock

squirrelscan version

0.0.102

Platform

Linux (glibc), Fedora 44

Command run

squirrel audit https://copperinteractive.com -C full --refresh --format llm

Reproduction

Any page on https://copperinteractive.com (static HTML served by Cloudflare Workers Assets). With the same User-Agent squirrel records in pages.request_headers:

curl -s -D - -o /dev/null \
  -H "Accept-Encoding: gzip, deflate, br, zstd" \
  -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36" \
  https://copperinteractive.com/about/

returns:

cache-control: public, max-age=0, must-revalidate
etag: W/"ad66933fd8e64dd4529f856985df80eb"
content-encoding: zstd

Cloudflare turns the strong ETag into a weak one when it compresses the response. A request without compression gets the strong ETag.

Expected behavior

perf/bad-caching should count the page as declaring a caching policy, because it has a validator plus max-age=0 (the "revalidates" path in the rule docs), and as exposing a validator. A weak ETag is a valid validator for If-None-Match revalidation.

Actual behavior

The stored response headers for every page have "etag": null (and the pages.etag column is NULL), while cacheControl and contentEncoding: "zstd" are recorded correctly. The rule then fails both checks on 14/14 pages:

perf/bad-caching  fail  14/14 pages set no caching policy (no freshness lifetime and no validator); 14/14 pages lack an ETag or Last-Modified validator

I haven't confirmed whether the weak W/ prefix is the trigger or the header gets lost when the zstd body is decompressed. Either way, the header is on the wire and missing from the stored record.

Logs or report output

From ~/.squirrel/projects/copperinteractive-com/project.db, pages.headers for /about/:

{"contentType":"text/html","contentEncoding":"zstd","cacheControl":"public, max-age=0, must-revalidate","expires":null,"etag":null,"lastModified":null,"cfCacheStatus":"HIT", ...}

Triage notes (maintainer)

The ETag is present on the wire for Accept: */* and absent for the browser Accept: text/html squirrel sends (Cloudflare feature-dependent rewriting), so this is mostly CDN behaviour, not a parser bug. The rule should still say so instead of failing hard.

Acceptance Criteria

  • A weak ETag (W/"...") is recorded and counts as a validator for identity, gzip, br and zstd responses (regression test)
  • bad-caching-validators never fails: it caps at warning, bad-caching-freshness is unchanged
  • When at least half of the pages missing a validator came through Cloudflare (server: cloudflare, cf-cache-status or cf-ray), the finding adds a "may" note naming the documented causes and fixes
  • The shared CDN detection lives in one helper in @squirrelscan/utils, reused by the waf detection
  • docs/rules/perf/bad-caching.mdx and the CHANGELOG describe the cap and the note
  • A later issue tracks detecting JavaScript Detections (needs a stored field)

Activity

  1. self-assigned this
    on Oct 9, 2026
  2. added theissue type on Oct 9, 2026
  3. nc9 commented on Oct 9, 2026

    @nc9
    Contributor

    thanks will look into it

  4. nc9 commented on Oct 9, 2026

    @nc9
    Contributor

    it appears cloudflare may be removing the E-Tag here in this case - I think we can write something to detect this and recommend some cloudflare settings. leave it with me

  5. nc9 commented on Oct 9, 2026

    @nc9
    Contributor

    Thanks for the report. I looked into this and squirrelscan is not dropping the ETag: Cloudflare is not sending it when the request says it wants HTML, which is what squirrel (and every real browser navigation) sends. The W/ prefix and zstd are not the cause.

    The only difference between these two requests is the Accept header:

    $ curl -sI -H "Accept: */*" -H "Accept-Encoding: gzip" https://copperinteractive.com/about/
    HTTP/2 200
    cf-cache-status: HIT
    cache-control: public, max-age=0, must-revalidate
    etag: W/"81aecf1d5b0355e13ce3f856c1469b64"
    content-encoding: gzip
    
    $ curl -sI -H "Accept: text/html" -H "Accept-Encoding: gzip" https://copperinteractive.com/about/
    HTTP/2 200
    cf-cache-status: HIT
    cache-control: public, max-age=0, must-revalidate
    content-encoding: gzip

    curl's default Accept: */* keeps the ETag, Accept: text/html loses it, so a plain curl -I hides the problem. The same happens with Accept-Encoding: identity. For text/html requests Cloudflare rewrites the HTML (here it injects the Web Analytics beacon, static.cloudflareinsights.com/beacon.min.js), and a rewritten body loses its ETag. The page sends no Last-Modified either, so browsers have nothing to revalidate with, and the finding is accurate for real visitors.

    To fix it on your side, turn off automatic Web Analytics setup for the zone and add the beacon snippet to your pages manually (or turn off the other HTML-rewriting features: Email Address Obfuscation, Rocket Loader, Zaraz), or serve a Last-Modified header. Then re-run the curl above with Accept: text/html and you should see the etag line.

    On our side I'll add a note to the bad-caching rule docs and a test that weak ETags survive every encoding.

  6. added
    bug
    P3
    size: M
    rules
    on Oct 9, 2026
  7. nc9 commented on Oct 9, 2026

    @nc9
    Contributor

    Correction to my earlier comment: I said the missing ETag came from Cloudflare's Web Analytics beacon. That is only supported by a forum post, so please don't rely on it.

    What is documented: Cloudflare removes or weakens an ETag on HTML when a feature has to rewrite the body. The ones to check on the zone are Email Address Obfuscation, Automatic HTTPS Rewrites, "Replace insecure JS libraries", and JavaScript Detections (Bot Fight Mode turns that one on). squirrel sends a browser Accept: text/html, so it records what Chrome receives. A plain curl (Accept: */*) can still show an ETag.

    @doradorock, is Bot Fight Mode on for this zone? Turning off the rewrite features above, or sending Cache-Control: no-transform or a Last-Modified header from the origin, should bring a validator back.

    On our side we will:

    • cap the validators check at warning, since the page may be fine and the CDN is what changed the response;
    • add a note on that finding when most affected pages came through Cloudflare, worded "may";
    • add a test that a weak ETag survives identity, gzip, br and zstd.
  8. nc9 commented on Oct 9, 2026

    @nc9
    Contributor

    Fixed on main in #606 (will ship in the next release): the validators check no longer fails, and when most of the pages missing a validator came through Cloudflare the finding now says that Cloudflare may drop the ETag from HTML it rewrites, with the documented causes and fixes. A weak ETag is covered by a test across identity, gzip, br and zstd. Still interested in whether Bot Fight Mode was on for your zone.

  9. doradorock commented on Oct 9, 2026

    @doradorock
    Author
  10. nc9 commented on Oct 9, 2026

    @nc9
    Contributor

    All good - there was still an issue here where it needed to be communicated better back to users - so appreciate the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3bugrulessize: M

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions