Skip to content

feat(rules,utils): perf/bad-caching names Cloudflare JavaScript Detections #605 - #1358

Closed
nc9 wants to merge 2 commits into
mainfrom
feat/jsd-note-605
Closed

nc9 wants to merge 2 commits into
mainfrom
feat/jsd-note-605

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Closes #605

perf/bad-caching's validator note now names Cloudflare JavaScript Detections when the pages carry its script.

  • hasJavaScriptDetections(doc) in @squirrelscan/utils/cdn: a <script> that sets __CF$cv$params, references /cdn-cgi/challenge-platform/ inline, or loads it as src. Text that only mentions the path (visible text, <pre>) does not count. Bounded: at most 60 scripts per page, 2,048 characters of each.
  • New collected per-page signal edgeMarkers ("cf-jsd"), computed once per page from the live DOM in buildCollectedPageSignal; the resident engine (squirrel analyze) reads the document directly, so both engines agree.
  • The rule: when at least half of the pages missing a validator are behind Cloudflare and carry the marker, the note says JavaScript Detections was found on K of them (details.javascriptDetectionsPages); Cloudflare pages without the marker keep the headers-only note.
  • Rule-cache format change: the collector id is bumped to site-dom-signals-v2, so every older cache entry is a miss and each site's first audit after the upgrade runs fresh once (CHANGELOG says so).

Tests (bad-caching.test.ts, both engines): half or more with the marker names it, no marker keeps the headers-only note, fewer than half does not, path in visible text/<pre> does not count, external challenge-platform script counts, and a 1 MB script and 40,000 script tags finish in under 100 ms (the marker past the 2,048-character window of a huge script is not found: documented bound). rule-cache and golden suites pass.

Docs docs/rules/perf/bad-caching.mdx; CHANGELOG under Unreleased. Skill: none.

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1358. I read the diff and grepped for other uses of the renamed collector id. I did not run the tests.

  • (low) packages/rules/src/collected-signals.ts: the new edgeMarkers extractor runs for every page, not only Cloudflare ones. The script scan is bounded (60 scripts, 2 KB each), so the cost is small. Still, querySelectorAll("script") builds the full NodeList before the cap applies. On a page with 40k script tags that is an O(n) allocation per page. The test only asserts a 100 ms wall-clock threshold, which may flake on slow CI. Per AGENTS.md, prefer asserting an effect over elapsed time.
  • (low) packages/rules/src/performance/bad-caching.ts: in the streaming path, markersByUrl is keyed by rec.url and looked up by page.url. If the two ever differ (a redirect-final URL against the requested URL, or a trailing slash), the lookup silently misses and the rule falls back to the generic Cloudflare note. A comment, or one test where the URLs differ, would pin this down.
  • (nit) The template-verdict and golden pins are not mentioned. Changing the CollectedPageSignal shape and the collector id may move template-cluster-key-golden or the golden suite. Confirm they pass. The comment in template-cluster-key-golden.test.ts:329 still says "site-dom-signals".
  • (nit) JSD_MARKER is case-insensitive and unanchored. That is fine for a bounded slice, but a pre-existing non-Cloudflare site that references /cdn-cgi/challenge-platform/ in an inline script is only counted if detectCdnFromHeaders already says cloudflare. That is the right gate, and it is the behaviour you documented.

The collector-id rename is a reasonable way to invalidate stale cache entries. I found no remaining references that depend on the old id other than that comment and test fixtures. The docs and the CHANGELOG entry are present. I found no high-severity issues.

nc9 added 2 commits October 31, 2026 06:20
…tions when the pages carry its script #605

Signed-off-by: Nik Cubrilovic <[email protected]>
…g for Bot Fight Mode plans #605

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the feat/jsd-note-605 branch from bac185c to ea971ff Compare October 30, 2026 19:21
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1358: no blocking problems found. I read the diff but did not run the tests.

  • (low) packages/rules/src/performance/bad-caching.ts:130: markersByUrl is built on every run, including when collectedSignals is absent (the resident engine). Build it only when ctx.collectedSignals is set. The cost is small.
  • (low) packages/rules/src/performance/bad-caching.ts:167: the streaming path matches signals to pages by page.url. If a page is missing from collectedSignals (for example one skipped as a template-cluster copy), it reads as "no marker" and falls back silently to the headers-only note. It does so without flagging that the signal was never judged. Please confirm the collector runs for every page that reaches this rule.
  • (low) packages/utils/src/cdn.ts: only the first 2,048 characters of each of the last 60 scripts are scanned. A page that has the Cloudflare snippet and then more than 60 trailing scripts is a false negative. The result is a milder note, not a wrong one, and the bound is documented, so this is acceptable.
  • (nit) packages/rules/src/collected-signals.ts: the hasJavaScriptDetections import sits after the relative imports. Group it with the other package imports.
  • (nit) packages/rules/tests/bad-caching.test.ts: the new tests are long single lines that oxfmt would reflow. The timing assertion (<100 ms) could be flaky on a loaded CI runner. The 5,000-character case already shows the cap works, so you could drop the timing check.
  • (nit) The site-dom-signals-v2 id bump invalidates every cached rule result once, and the CHANGELOG says so. Good.

Docs and CHANGELOG are updated. Docs: updated. Skill: none.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.145 as 533fd7f2 c3506213 via #1377. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.145. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 2026
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.

feat(rules): name Cloudflare JavaScript Detections in the perf/bad-caching ETag note

1 participant