Skip to content

fix(waf-detect): JSD pages are not challenges, a provider's name is not its signature (#666, #667) - #692

Merged
nc9 merged 6 commits into
mainfrom
fix/waf-detect-666-667
Oct 12, 2026
Merged

nc9 merged 6 commits into
mainfrom
fix/waf-detect-666-667

Conversation

@nc9

@nc9 nc9 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #666
Closes #667

What changed

#666, JavaScript Detections read as a challenge. Cloudflare's JavaScript Detections (Bot Fight Mode turns it on) injects a script into ordinary pages that loads /cdn-cgi/challenge-platform/scripts/jsd/main.js. /challenge-platform/i was a challenge-interstitial marker, so any 200 page from Cloudflare with the snippet in its first 10 KB was classified as a challenge and set aside from page-level scoring. The same bare-directory check in the agent-access probe (packages/crawler/src/agent-access.ts) made ax/agent-blocking FAIL with "Claude-User is blocked (bot challenge (challenge-platform))" on such a homepage.

  • packages/waf-detect/src/providers.ts: challenge markers are split into CHALLENGE_MARKUP_PATTERNS (only a challenge or block page carries them: the challenge's own script CLOUDFLARE_CHALLENGE_SCRIPT = /cdn-cgi/challenge-platform/(h/<x>/)?orchestrate/, _cf_chl_opt, __cf_chl_, cf-browser-verification, Imperva's incident line with its id, Akamai's entity-encoded reference or its reference id after "Access Denied", PerimeterX's captcha) and CHALLENGE_TEXT_PATTERNS (wording any page can say: "just a moment", "checking your browser", access denied + reference).
  • challenge.ts: markup counts with a challenge status (401/403/429/503) or WAF attribution, as before; wording now counts only with a challenge status.
  • agent-access.ts: the challenge script or __cf_chl_ / _cf_chl_opt in the first 10 KB, and a <title> starting "Just a moment" (attributes allowed) in the first 4 KB, instead of the bare directory and the phrase anywhere in the first 4 KB.

#667, a provider's name as its signature. CONTENT_PATTERNS (body attribution, used for the report's technologies, the challenge gate on 200 pages, and 403 classification of external links) matched /imperva/i, and the same shape existed for most providers. Checked every provider and replaced each prose pattern with what the provider's infrastructure emits:

Provider Removed Now
Imperva /imperva/i, /powered by incapsula/i, bare incapsula incident id incident line with its id (tags allowed between), /_Incapsula_Resource
DataDome /datadome/i, /dd\.js/ (matched add.js) js.datadome.co, captcha-delivery.com, ddjskey
PerimeterX /perimeterx/i px-captcha, _pxCaptcha, _pxAppId, client.perimeterx.net
Kasada /kasada/i, /ips\.js/i (matched tips.js), /cd\.js/ (matched abcd.js) window.KPSDK, KPSDK.configure, ips.js under Kasada's two-UUID path
Sucuri /sucuri website firewall/i the block page's title and heading in full
Akamai /access denied.*akamai/i, /reference\s*#\s*[\d.]+/i (matched "Reference #3") dotted reference id 18.9d367a83.1614887475.2b3c78d, entity form, errors.edgesuite.net
Cloudflare /checking your browser/i, /cloudflare ray id/i the full IUAM line, ray id with its hex value, _cf_chl_opt, /cdn-cgi/challenge-platform/ (attribution only: a JSD page IS on Cloudflare)

CHALLENGE_INTERSTITIAL_PATTERNS is replaced by the two lists above (no consumers outside the package; @squirrelscan/utils/waf re-exports updated).

Behaviour changes worth knowing: sites with JSD get their pages scored, so their scores change (the fixture below went from 97, computed from site rules alone, to 50 with its three pages scored). A headerless 403 whose body only named a provider is now an ordinary refusal in external link checks.

Acceptance evidence

BEFORE = squirrel 0.0.108 binary, AFTER = CLI from this branch, audit <fixture> --http --refresh -m 5 -f json, local fixtures (Cloudflare headers server: cloudflare, cf-ray, cf-cache-status; pages listed in a sitemap):

Fixture BEFORE AFTER
#666: 3 small 200 pages with the JSD snippet Detected 3 challenge/interstitial page(s) via Cloudflare; these pages were excluded from page-level rule scoring.; ax/agent-blocking fail "Claude-User is blocked (bot challenge (challenge-platform))" + warn for GPTBot no challenge finding, 3 pages scored, no ax/agent-blocking issue, still attributed to Cloudflare
JSD home + two 403 cf-mitigated: challenge managed-challenge pages home counted as a challenge, agent-blocking fail home scored, no agent-blocking issue (the 403 pages are refusals at the crawler, unchanged)
#667: 200 nginx pages that discuss Imperva ("Just a moment of setup") Detected 1 challenge/interstitial page(s) via Imperva/Incapsula; technologies Imperva/Incapsula (high); agent-blocking fail (just-a-moment) no challenge finding, no Imperva technology, no agent-blocking issue
Imperva block page (/_Incapsula_Resource iframe + incident line) behind an ordinary home Detected 1 ... via Imperva/Incapsula unchanged: Detected 1 challenge/interstitial page(s) via Imperva/Incapsula

Unit tests: packages/waf-detect/tests/content-signatures.test.ts (new): JSD-only small page at 200 is not a challenge but is Cloudflare; a managed challenge at 403/503 and 200 is "Cloudflare"; wording alone needs a challenge status; a prose roundup naming every provider attributes nothing and is not a challenge; the Imperva block page is Imperva at 200 and 403; one positive per provider signature (18) and 13 prose/filename negatives; Akamai deny page at 200 in both forms; a page quoting an Akamai reference is not a challenge; headerless 403 isLikelyWafBlock per provider and for prose. packages/crawler/tests/ax-prefetch.test.ts: orchestrate script, _cf_chl_opt, JSD and in-text "Just a moment" negatives, a challenge whose scripts sit past the 4 KB head caught by its attributed <title>. apps/cli/tests/utils/waf.test.ts: two fake ray ids (xyz) made realistic.

Local gates: tsgo --noEmit clean in packages/waf-detect, utils, crawler, audit-engine and apps/cli. Tests, explicit files, all pass: the new waf-detect file; crawler ax-prefetch, status-guards, full-crawl-harness, root-failure-classification, render-reuse-source-hash; cli utils/waf, audit/adapter-waf, crawler/cloud-fetcher; audit-engine soft404-confirm, waf-tech-set-cookie, cloud-tech-section, failure-classification, page-features-noindex-golden, streaming-rules-golden, streaming-sitequery-universe-golden, cloud-prefetch, rate-limited-pages-e2e, refused-fetches-e2e; rules agent-blocking, pay-per-crawl, rate-limited-links; utils fingerprint, cdn; fetchers conditional-render. oxfmt/oxlint clean on the touched CLI test. scripts/test-suites.ts --check ok. Docs [email protected] check --strict passes. Two codex rounds; fixed: a 200 Akamai deny page lost, an attributed <title> missed, Imperva line with tags, KPSDK/Sucuri prose, an Akamai reference quoted in help text, doc wording.

Docs: docs/guides/failed-audits.mdx (#waf-challenge: what a recognised challenge body is, wording needs a challenge status, JSD never counts, same test for page exclusion), docs/rules/ax/agent-blocking.mdx (what counts as a bot challenge for the probes, the reason strings). CHANGELOG under Unreleased / Fixed.

Agent skill (squirrelscan/skills): no change needed; the skill does not describe WAF or challenge detection.

Follow-ups (not fixed here)

  • waf-detect: a page that quotes a provider's signature in text is still attributed to it #693: body signatures are still regexes over raw text, so a page that QUOTES a real signature (a tutorial showing window.KPSDK, js.datadome.co, or an Incapsula incident ID: 123 line) is still attributed. Closing that needs DOM context (script src and inline script bodies only), not more patterns.
  • The agent-access probe now reads challenge scripts in the first 10 KB (like waf-detect) and the title in the first 4 KB; a challenge with no cf-mitigated header, another title and its scripts past 10 KB is still missed.
  • The body patterns are written against fixtures shaped like each provider's block page, not captured ones; a set of real captured block pages per provider would make the positives evidence rather than assumptions.

…ot its signature #666 #667

#666: Cloudflare JavaScript Detections loads a script from
/cdn-cgi/challenge-platform/ on ordinary pages, and the bare directory
was a challenge marker, so a small 200 page through Cloudflare was set
aside from scoring and ax/agent-blocking reported GPTBot and Claude-User
as blocked. Challenge markers are now split: markup only a challenge
carries (the orchestrate challenge script, _cf_chl_opt, __cf_chl_,
Imperva's incident line, Akamai's reference after its denial) and
wording any page can say ("Just a moment"), which counts only on a
401/403/429/503. The agent-access probe uses the challenge script,
_cf_chl_opt and the "Just a moment" title.

#667: body attribution matched provider names in prose (/imperva/i and
the same shape for DataDome, PerimeterX, Kasada, Sucuri, Akamai and
Cloudflare) and unanchored script names (dd.js, ips.js, cd.js). Every
provider's body patterns are now infrastructure it emits: script and
captcha hosts, client objects, block-page titles and reference formats.

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

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #692 (JSD pages no longer read as challenges, provider names no longer used as signatures)

No blocking problems found. The split into markup and text patterns is sound, and no references to the removed CHALLENGE_INTERSTITIAL_PATTERNS remain in the repo. I read the diff only and did not run the tests.

  • (low) packages/crawler/src/agent-access.ts:37 The title check covers a challenge whose scripts sit past the 4 KB head. A challenge with an unusual or localized title and its _cf_chl_opt or orchestrate script past 4 KB is still missed. The PR already lists this as a follow-up. It would be cheap to also check _cf_chl_opt and the orchestrate script against a larger slice, such as 10 KB, matching challenge.ts.
  • (low) packages/waf-detect/src/providers.ts The Sucuri patterns use a plain - (\s*-\s*). If a block page renders the dash as &#8211;, &ndash; or an en-dash, it won't match. The same applies to the Imperva incident line if the colon is entity-encoded. Consider (?:-|–|&#8211;|&ndash;) if captured pages show this. The PR admits the patterns are written against fixtures and not captured pages.
  • (low) providers.ts The Cloudflare attribution pattern /\/cdn-cgi\/challenge-platform\// stays in CONTENT_PATTERNS. This is intentional and tested, but it means any page quoting that path is attributed to Cloudflare. The PR notes the DOM-context follow-up. Worth tracking in an issue.
  • (nit) challenge.ts Add a one-line comment that "markup" is checked before "text" on purpose. The precedence matters because a page with both counts as markup.
  • (nit) The access denied[\s\S]{0,2000}?<reference id> regex is bounded and runs on a 10 KB sample, so it is fine for ReDoS. A short comment saying so would stop a later edit from removing the bound.

Test coverage is strong: positives and negatives per provider, status gating, the 4 KB head case, and headerless-403 behaviour. The CHANGELOG and docs are updated, and the score change on affected sites is documented.

…cept en dashes and entity colons #666 #667

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

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the review, fixed in b19fdcf:

  • agent-access window: done. Challenge-only markup (the orchestrate script, __cf_chl_, _cf_chl_opt) is now looked for in the first 10 KB, as in waf-detect; the title stays a 4 KB check. Tests: a German-titled challenge whose _cf_chl_opt sits past 4 KB is caught by the script, and one whose scripts sit past 10 KB is still caught by its attributed <title>. The agent-blocking docs say so.
  • Dashes and entity colons: done. Sucuri's title/heading patterns accept -, an en dash, &#8211; and &ndash;; Imperva's incident line accepts &#58;. Tests for each.
  • /cdn-cgi/challenge-platform/ attribution and quoted signatures in general: tracked as waf-detect: a page that quotes a provider's signature in text is still attributed to it #693 (read signatures from <script src>, inline scripts and <iframe src> only).
  • Markup-before-text precedence and the bounded Akamai gap: commented in challenge.ts and providers.ts.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #692 (JSD false-positive challenge + provider-name signatures)

I read the full diff. I did not run the test suite.

The change is well scoped. Splitting challenge markers into markup (challenge-only) and text (any page can say it) is a clean model. The gating in challenge.ts is correct: text needs a challenge status, markup needs a status or WAF attribution. The new content-signatures.test.ts covers both directions: real challenge and block pages still match, and prose plus JSD pages no longer do.

  • (low) packages/waf-detect/src/providers.ts: the new Akamai pattern access denied[\s\S]{0,2000}?<reference id> is bounded, but it re-scans up to 2 KB from every "access denied" occurrence in the 10 KB sample. The worst case is a page that repeats the phrase many times, which is roughly 10 KB × 2 KB of work per page. That is acceptable, but a short comment or a test with a pathological input would make the linear-scan claim in the comment checkable.
  • (low) providers.ts / CLOUDFLARE_CHALLENGE_SCRIPT: the h/<x>/ segment is a single letter ([a-z]). This matches today's /h/b/ and /h/g/. If Cloudflare ever uses a longer path segment, detection quietly drops back to _cf_chl_opt and __cf_chl_, which are still present on managed challenges, so the risk is small. (?:h\/[a-z0-9_-]+\/)? would be more tolerant.
  • (low) providers.ts: Cloudflare's CONTENT_PATTERNS still includes the bare /cdn-cgi/challenge-platform/. This is intentional: JSD pages stay attributed to Cloudflare, and a test asserts it. It is worth keeping the comment explicit that attribution is not challenge detection, because a later edit could reuse it as one.
  • (nit) agent-access.ts: the title check only looks in the first 4 KB, while the other markers use 10 KB. The tests show the tradeoff is deliberate, so a short comment on why 4 KB is enough for the title would help.
  • (nit) Dropping /imperva/i, /datadome/i and similar patterns means headerless block pages that carry only the provider's name are no longer attributed. The CHANGELOG already says so. That is reasonable, and it is a behaviour change users may notice in the report's technologies list.

I found no correctness, security or test-coverage problems that should block the merge.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Second review, f0dded0:

  • Akamai gap scan: the comment now states the actual bound (each "access denied" in the 10 KB sample costs at most a 2 KB scan, not "linear"), and a test runs 600 repetitions without a reference and asserts it stays fast.
  • CLOUDFLARE_CHALLENGE_SCRIPT: the h/ segment now accepts any [\w-]+, so a longer segment still matches.
  • Attribution-only /cdn-cgi/challenge-platform/: commented in CONTENT_PATTERNS as attribution, never challenge detection, pointing at CLOUDFLARE_CHALLENGE_SCRIPT.
  • Title window: commented (the title opens the document, so 4 KB holds it on a real challenge).
  • Name-only headerless block pages: agreed, intended, and in the CHANGELOG.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff (detection logic, agent-access probe, docs, tests). I found no blocking problems. The change fits the problem. It splits challenge markers into markup and text, requires a challenge status for text-only matches, and swaps provider names for signatures the provider's own infrastructure emits.

  • (low) packages/crawler/src/agent-access.ts: the title check only looks at the first 4 KB. A challenge with a non-English title and a long inline style block before its script can fall between the 4 KB title window and the 10 KB script window. The tests cover each case separately. I'd accept this, but a one-line comment saying it's a known gap would help.
  • (low) packages/waf-detect/src/providers.ts: the new signatures are exact and some are narrow, e.g. the Kasada UUID path and the Sucuri title with dash variants. A vendor markup change will turn those into silent false negatives. The tests pin today's formats, so refreshing them occasionally is worth a note in the docs or CONTRIBUTING.
  • (nit) access denied[\s\S]{0,2000}?<reference id> is bounded and has a timing test. The 500 ms threshold could flake on slow CI runners, so a looser bound or a match-count check might be more stable.
  • (nit) agent-access.ts imports CLOUDFLARE_CHALLENGE_SCRIPT from @squirrelscan/utils/waf. That is fine, but check that the crawler package already depends on utils and that the export is in the built entry point.

Test coverage is good. It covers JSD pages, real challenges, prose mentions per provider, headerless 403s and the regex performance case.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Third review: no code change, triage below.

  • 4 KB title vs 10 KB script windows: the remaining gap (another-language title AND scripts past 10 KB AND no cf-mitigated header) is listed in the PR's follow-ups; a real managed challenge also carries cf-mitigated: challenge, which is checked first.
  • Narrow signatures going stale: agreed that is the tradeoff of infrastructure signatures. The PR's follow-ups name a captured-block-page fixture set as the way to keep them honest, and waf-detect: a page that quotes a provider's signature in text is still attributed to it #693 tracks reading them from DOM context.
  • 500 ms timing bound: the scan is about 1.2M characters at worst (600 occurrences × 2 KB) and runs in well under 10 ms locally, so 500 ms leaves two orders of magnitude for a slow runner.
  • @squirrelscan/utils/waf from the crawler: the crawler already depends on @squirrelscan/utils and already imports detectWafChallengePage from @squirrelscan/utils/waf in fetcher.ts; packages export TypeScript source, there is no separate build entry. tsgo --noEmit is clean in crawler, utils, waf-detect, audit-engine and apps/cli.

…ord boundary (CodeQL missing-regexp-anchor) #667

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

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #692. The change is well-reasoned and the tests cover the new signatures. I found no blocking issues.

  • (low) packages/waf-detect/src/index.ts, packages/utils/src/waf.ts: CHALLENGE_INTERSTITIAL_PATTERNS is removed from the public exports. I grepped the repo and found no remaining non-test users. If external consumers of @squirrelscan/waf-detect exist, this is a breaking change, so consider a changelog note or a deprecated alias.
  • (low) packages/waf-detect/src/providers.ts: the removed provider-name patterns (/datadome/i, /kasada/i, /perimeterx/i) reduce recall for sites that only reference the vendor by name, for example a first-party proxied script path. That is the intended trade-off for fix(waf-detect): the /imperva/i content pattern attributes any page that mentions Imperva to Imperva #667. A short test showing a real proxied DataDome or PerimeterX deployment still attributes would be reassuring.
  • (low) providers.ts, Akamai pattern access denied[\s\S]{0,2000}?<reference id>: it is bounded, so there is no ReDoS. Cost is at most about 2 KB per access denied occurrence in the 10 KB sample, and I don't expect it to matter.
  • (nit) agent-access.ts: CLOUDFLARE_CHALLENGE_SCRIPT has no g flag, so .test is stateless. Worth keeping that way, since the regex is now shared and exported. A comment on the export would stop someone adding g later.
  • (nit) agent-access.ts: the reason string is still challenge-platform even though the match is now the orchestrate script. This is fine for compatibility with the docs, but it is slightly misleading.

…oads them (CodeQL missing-regexp-anchor) #667

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

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the source changes (agent-access, waf-detect providers/challenge, utils re-exports). I found no blocking problems. The removed CHALLENGE_INTERSTITIAL_PATTERNS export has no remaining references in the repo.

  • (low) packages/crawler/src/agent-access.ts:36 detectChallenge no longer takes the HTTP status into account. The old bare challenge-platform check matched any page. The new one needs the orchestrate/ script, _cf_chl_opt or a <title>Just a moment. A real managed challenge should still match. A Cloudflare variant that serves the challenge from a different path, or whose title is localized (the challenge title is translated per locale), would now be missed, so ax/agent-blocking would under-report blocking. Consider a test with a non-English title or a different script path to make the tradeoff explicit.
  • (low) packages/waf-detect/src/providers.ts The Kasada, DataDome and Imperva pattern narrowing trades false positives for false negatives. A site whose WAF script loads from a first-party path is no longer attributed. This seems intentional given fix(waf-detect): the /imperva/i content pattern attributes any page that mentions Imperva to Imperva #667. The content-signature tests should cover one positive case per provider, so a narrowed pattern can't silently stop matching.
  • (nit) providers.ts access denied[\s\S]{0,2000}?<akamai ref> is bounded and lazy, so ReDoS is not a concern. The 10 KB sample cap keeps the cost small.
  • (nit) The CHALLENGE_MARKUP_PATTERNS and CHALLENGE_TEXT_PATTERNS split reads clearly. A one-line note in the CHANGELOG that the old constant was removed from the public @squirrelscan/utils/waf export would help anyone importing it.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Fourth review (on 1120d18, which also clears the two CodeQL missing-regexp-anchor alerts by matching the DataDome and PerimeterX hosts where a script loads them, src=): no code change.

  • Localized titles / other script paths in detectChallenge: covered. ax-prefetch.test.ts has a German-titled challenge ("Einen Moment bitte...") caught by _cf_chl_opt within 10 KB, and an attributed English title caught when the scripts sit past 10 KB. A managed challenge also sends cf-mitigated: challenge, checked first. The one remaining gap (localized title, scripts past 10 KB, no header) is in the PR's follow-ups.
  • Narrowing trades false positives for false negatives: intended for fix(waf-detect): the /imperva/i content pattern attributes any page that mentions Imperva to Imperva #667 and stated in the CHANGELOG. content-signatures.test.ts has at least one positive per provider (two to four for most), so a narrowed pattern cannot stop matching silently.
  • Removed CHALLENGE_INTERSTITIAL_PATTERNS: @squirrelscan/utils and @squirrelscan/waf-detect are private workspace packages ("private": true), not published, and nothing in either repo imports it, so there is no outside consumer to tell.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff for the waf-detect, utils and crawler changes. I didn't run the tests.

  • (low) packages/crawler/src/agent-access.ts: the challenge check now needs the orchestrate/ script, __cf_chl_/_cf_chl_opt, or a <title>Just a moment in the first 4 KB. A challenge page that puts <title> after more than 4 KB of inline content, or a localized challenge title, will no longer be flagged. The Cloudflare script and _cf_chl_opt checks (10 KB) still cover the common managed challenge, so the risk is small. A test for the localized-title case would document it.
  • (low) packages/waf-detect/src/providers.ts: CHALLENGE_MARKUP_PATTERNS builds access denied[\s\S]{0,2000}?<reference id>. The 2 KB bound keeps it linear, which is good. Add a test where the 10 KB sample has many "access denied" strings, so a future edit doesn't make it a backtracking hazard.
  • (nit) The CHALLENGE_INTERSTITIAL_PATTERNS export is removed from @squirrelscan/waf-detect and @squirrelscan/utils/waf. A grep shows no remaining in-repo users, but it is a public-API break for external consumers. Mention it in the CHANGELOG or keep a deprecated alias.
  • (nit) The comment above CHALLENGE_200_SIGNATURES in providers.ts is now one very long line. Wrap it.

Overall the change is well-reasoned and well-tested. It narrows the false positives from #666 and #667 without dropping real challenge signals. I found nothing blocking.

@nc9
nc9 merged commit 600adf9 into main Oct 12, 2026
15 checks passed
@nc9
nc9 deleted the fix/waf-detect-666-667 branch October 12, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants