Skip to content

fix(rules): cap bad-caching validators at warn and note a Cloudflare-stripped ETag (#600) - #606

Merged
nc9 merged 4 commits into
mainfrom
fix/bad-caching-cdn-note
Oct 9, 2026
Merged

nc9 merged 4 commits into
mainfrom
fix/bad-caching-cdn-note

Conversation

@nc9

@nc9 nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Closes #600

What changed

perf/bad-caching no longer fails a site whose HTML lost its ETag at the edge, and it says when Cloudflare is the likely cause.

  • New helper @squirrelscan/utils/cdn: detectCdnFromHeaders(headers) returns "cloudflare" or null. It takes a Headers or the header map rules see, rehydrates through recordToHeaders, and calls detectWafFromHeaders, so Cloudflare (cf-ray, server: cloudflare, cf-cache-status) still has one definition, in waf-detect's header table.

  • bad-caching-validators caps at warn. It never fails now. A page with no lifetime and no validator already counts against bad-caching-freshness, which is unchanged (status, thresholds, message).

  • Cloudflare note. When the validators check warns and at least half of the pages missing a validator came through Cloudflare, the message ends with:

    K of them came through Cloudflare, which may drop the ETag from HTML it rewrites with Email Address Obfuscation, Automatic HTTPS Rewrites, Replace insecure JavaScript libraries or JavaScript Detections (Bot Fight Mode). Add no-transform to the HTML Cache-Control, turn those features off, or also send Last-Modified

    details.cloudflarePages carries K for JSON consumers. The note never changes a status. It sits in the message because the LLM report prints only check messages. No new stored field, no rule-cache format change.

  • Docs: docs/rules/perf/bad-caching.mdx says the validators check never fails, that weak ETags count, shows two curl commands that tell an Accept-gated removal apart, lists the fixes (with the no-transform caveats) and quotes the note template. CHANGELOG entry under [Unreleased].

Tests

  • packages/rules/tests/bad-caching.test.ts: validators warn, never fail (0% and 40%); max-age=0 with no validator still fails freshness; a weak ETag under max-age=0, must-revalidate passes both checks for identity, gzip, br and zstd; the exact note message; server: cloudflare alone; no note without Cloudflare; exactly half fires and under half does not; the denominator is missing pages, not all pages; Cloudflare pages that kept a validator do not count; a passing check (and the 60% boundary) carries no note; freshness message unchanged.
  • packages/utils/tests/cdn.test.ts: each Cloudflare header alone, case-insensitive server, Headers input, other CDNs, mixed providers, and header values Headers would reject.
  • packages/crawler/tests/validator-headers.test.ts: fetchPage stores weak and strong ETags plus Last-Modified verbatim on identity, gzip, br and zstd responses, and an origin that drops the ETag for Accept: text/html is recorded without one, which pins that squirrel requests pages the way a browser does.

Verification

  • bun test on the three files above: 50 pass. golden-baseline.test.ts once: 6 pass.
  • tsgo --noEmit in packages/utils, packages/rules, packages/crawler: clean.
  • oxlint (CLI config) clean on the changed files; oxfmt applied to the new files only (the existing rule and test files were not oxfmt-formatted before, so I left their layout alone).
  • detect-secrets hook on the changed files: clean, baseline unchanged.
  • make validate in docs/: all checks passed.
  • Smoke: squirrel audit https://docs.squirrelscan.com -m 5 --refresh --no-publish -f llm from source. The finding reads 5/5 pages set no caching policy (no freshness lifetime and no validator); 5/5 pages lack an ETag or Last-Modified validator. 5 of them came through Cloudflare, .... The rule still reports status="fail" because freshness fails, as intended.

Notes

Skill

No change needed to the squirrelscan agent skill. Findings link to the rule docs, and the docs carry the fix.

nc9 added 4 commits October 9, 2026 22:57
…ders #600

detectCdnFromHeaders takes a Headers or the header map rules see and asks waf-detect's header table, so Cloudflare (cf-ray, server: cloudflare, cf-cache-status) has one definition. Exported as @squirrelscan/utils/cdn.

Signed-off-by: Nik Cubrilovic <[email protected]>
…stripped ETag #600

bad-caching-validators now warns instead of failing: a page with no lifetime and no validator already counts against bad-caching-freshness, which is unchanged. When the check warns and at least half of the pages missing a validator came through Cloudflare, the message adds a note that Cloudflare may drop the ETag from HTML it rewrites (Email Address Obfuscation, Automatic HTTPS Rewrites, Replace insecure JavaScript libraries, JavaScript Detections) and lists the fixes, and details carries cloudflarePages. Tests pin weak ETags as validators for identity, gzip, br and zstd, the cap, and the note thresholds.

Signed-off-by: Nik Cubrilovic <[email protected]>
…coding #600

fetchPage stores ETag and Last-Modified verbatim on identity, gzip, br and zstd responses, and requests pages with a browser Accept, so an origin that drops the ETag for HTML is recorded without one.

Signed-off-by: Nik Cubrilovic <[email protected]>


The rule page says the validators check never fails, that weak ETags count, how to tell with two curl requests whether Cloudflare removes the ETag, the fixes, and quotes the note template. CHANGELOG entry under Unreleased.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review October 9, 2026 12:10
@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review of PR 606 (perf/bad-caching Cloudflare note).

No (high) or (critical) findings. I read the diff and checked the wiring but did not run the tests.

  • (low) packages/rules/src/performance/bad-caching.ts: the validators check no longer ever returns fail, so a site where every page lacks a validator now scores better than before. The changelog and comments justify this because freshness already fails for pages with no lifetime. It only holds when pages have no max-age. A site with max-age=600 and no validators used to fail and now warns. Please confirm that is intended.
  • (nit) bad-caching.ts: cloudflareNote hardcodes the feature list in the message. If Cloudflare renames those features, the text in the rule and in the docs will drift. This is minor.
  • (nit) packages/crawler/tests/validator-headers.test.ts: the Accept-header test only checks that the fetcher sends text/html. It does not test anything about Cloudflare, which is fine, but the comment could say so.

Positives:

  • @squirrelscan/waf-detect is already a dependency of @squirrelscan/utils, and the new ./cdn export is declared.
  • The threshold edge cases for the note and for the 60% pass boundary are well covered by the new tests.
  • The note never changes the check status, which keeps the attribution separate from scoring.

🤖 Generated with Claude Code

@nc9
nc9 merged commit 2c1edd7 into main Oct 9, 2026
16 checks passed
@nc9
nc9 deleted the fix/bad-caching-cdn-note branch October 9, 2026 12:11
nc9 pushed a commit that referenced this pull request Oct 9, 2026
* origin/main:
  feat(rules): escalate server-only secrets shipped in browser scripts to critical (#575)
  fix(rules): cap bad-caching validators at warn and note a Cloudflare-stripped ETag (#606)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant