Skip to content

feat(crawler,waf-detect): fail the audit on WAF and bot challenge pages, list blocked pages #1253 - #1257

Merged
nc9 merged 8 commits into
mainfrom
fix/waf-challenge-detection-1253
Oct 29, 2026
Merged

nc9 merged 8 commits into
mainfrom
fix/waf-challenge-detection-1253

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1253.

What changed

Detection (packages/waf-detect): classifyWafResponse / inspectWafChallengePage return a verdict (blocked, suspect, clear), the provider and the matched signal. Twelve providers: Cloudflare, Akamai, DataDome, Kasada, HUMAN (PerimeterX), Imperva, Sucuri, AWS WAF, F5, Vercel, Wordfence, Radware. Every rule is a provider-specific header or page marker plus the status and page-size shape that provider's block page has. A vendor name, a vendor script on a normal page, or a CAPTCHA widget never counts. WafProvider is unchanged (the cloud's stored link-check results use it); the added providers are a new WafBlockProvider superset.

Crawler: a blocked response fails the fetch (any status, 429 included: a provider challenge is not throttling) and carries provider and signal. CrawlStats.wafBlocked records the seed block and up to 50 other blocked pages. The seed is identified by URL, not by source, because a sitemap listing the homepage enqueues it first.

Status and reports: a blocked seed makes the audit blocked with no score (even when other pages were fetched), statusReasonCode: http_4xx, reason ... blocked_by_<provider>: <Provider> served a challenge or block page (<signal>), HTTP <status>, for <host>. squirrel audit exits 3. Other blocked pages are never audited or scored and are counted and listed in console, text, markdown, llm, json and html (wafBlocked). The "Site uses X protection" warning is unchanged.

Evidence for each provider

  • Live responses, captured 2026-10-29 from public sites with light touch (Vercel x-vercel-mitigated and the HUMAN branded challenge confirmed by the maintainer's OVH captures too): Cloudflare (managed challenge with cf-mitigated, header-only challenge, "Attention Required!" block), Akamai deny at 403 and at 200, DataDome (two shapes), HUMAN block page and x-px-blocked, Kasada 429.
  • Vendor documentation: AWS WAF (x-amzn-waf-action, 202 challenge, 405 CAPTCHA; the body is built from the documented behaviour).
  • Public reports, not seen live: Vercel, Imperva interstitials, Sucuri, F5, Wordfence.
  • Not seen: Radware (host recalled).
  • Not recognised, no public marker tells their block from a refusal: Netlify, Fastly Next-Gen WAF. Both stay a plain 403 (access denied).

Fixtures say which origin each shape has (packages/waf-detect/tests/fixtures/waf-blocks.ts). Run over 29 real responses (11 good 200 pages included): every live block classified, no 200 page misclassified.

Offline detection against the maintainer's captures (scope addition)

Run over the 56 sanitised captures (13,357-site OVH batch): all 33 block samples are blocks with the right provider (Cloudflare challenge 403/429, Cloudflare "Attention Required", Vercel Security Checkpoint 429, DataDome, HUMAN including a restyled challenge, Akamai) and all 23 negatives (200 content behind Akamai, DataDome, Imperva, Kasada/BotID, Sucuri, Cloudflare JS Detections) are not. The only miss was a restyled HUMAN challenge (it keeps the px-captcha mount point): fixed. The synthetic fixtures are derived from the shapes, not copies. Technologies: Akamai, DataDome, Imperva, Sucuri, Cloudflare and Kasada (BotID, on top of Vercel) are reported for 200 content (waf-technologies-1253.test.ts). Neither misattribution reproduces on current main with the captured evidence (Sucuri is not attributed to Vercel or GitHub Pages headers; BotID is a technology and never a block); regression tests pin both. Five negatives (Akamai-04, DataDome-01/02, Kasada-01/02/03/06, Sucuri-01) carry no provider evidence in the capture (empty bodies, Vercel/nginx/Caddy headers only), so no provider can be shown for them.

Safety

Regexes run over a 32 KB prefix; pages over 100 KB are never "near-empty". Hostile 1 MB inputs (8 shapes) return in under 3 ms; a normal 50 KB page costs about 0.4 ms. Host regexes are anchored (src= context, no trailing host) with look-alike near-misses. Site-chosen fields are sanitised and escaped in every renderer.

Commands run

  • tsgo --noEmit in waf-detect, utils, core-contracts, crawler, audit-engine, report, apps/cli
  • bun run lint, format:check in apps/cli; bun run lint in packages/report
  • bun run scripts/test-suites.ts --check; --run report (984), --run crawler (839)
  • explicit-path tests: waf-detect (3 files), crawler status-guards, audit-engine waf-seed-block-1253, failure-classification, rate-limited-status, soft404-confirm, tech-detect-header-names-871, waf-tech-set-cookie, streaming-rules-canonical-golden, cli console-waf-blocked-1253, adapter-waf, scoring
  • make validate in docs; detect-secrets-hook --baseline .secrets.baseline on changed files
  • local end-to-end: squirrel audit against a fixture site (seed challenge at 200 with the sitemap listing it: exit 3; challenge on a non-seed page: audited, listed)

Follow-ups

  • Exit code 3 is new (1 stays operational failure, 2 the --fail-on gate).
  • The stored-page checks in the engine still run as a backstop for crawls recorded before this change.

Docs: docs/guides/failed-audits.mdx (new section, provider table, remedies), docs/cli/audit.mdx and docs/guides/ci.mdx (exit code 3), docs/configuration/output.mdx (wafBlocked), docs/configuration/crawler.mdx. Skill: yes, the agent skill needs a note on the blocked status, exit code 3 and wafBlocked.seed.code; a private issue with the skills label is for the maintainer to file.

nc9 added 7 commits October 29, 2026 13:51
…ders across 200/202/403/405/429/503 #1253

Provider-specific headers and page markers plus status and page-size gates,
with a verdict (blocked, suspect, clear) and the matched signal. Per-provider
real-shaped fixtures, each with a near-miss that must stay clear.

Signed-off-by: Nik Cubrilovic <[email protected]>
… other blocked pages #1253

The crawler records provider, signal and status for a blocked fetch (the seed by
URL, since a sitemap can enqueue it first). A blocked seed makes the audit
blocked with no score and exit code 3; other blocked pages are left out of rule
evaluation and listed in the console, text, markdown, llm, json and html
outputs. A provider challenge served as 429 is no longer treated as throttling.

Signed-off-by: Nik Cubrilovic <[email protected]>
… real block and negative classes and the provider technologies #1253 [skip ci]

Signed-off-by: Nik Cubrilovic <[email protected]>
…ck text; Vercel BotID and F5 BIG-IP as technologies #1253

Signed-off-by: Nik Cubrilovic <[email protected]>
…efusal and its app id, drop a regex trim #1253

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

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Reviewed the detection, crawler, report and CLI changes. I did not run the test suites. The design is careful: every rule needs a provider-specific marker plus a status or size shape, and report fields are sanitised at the renderer. Findings:

  • (medium) packages/crawler/src/fetcher.ts:1302 The new applyWafGuard runs only on the standard fetch path. The impersonation/cloud-render path (~line 996) still calls only applyStatusGuards. A 200/202/405 challenge served there (Akamai, DataDome, F5, AWS WAF) is still stored and audited as the site, so seed-block behaviour depends on which fetcher was used. Call it on that path too, or document the limitation.
  • (medium) packages/waf-detect/src/classify.ts (Cloudflare challenge script, Imperva incident id and Sucuri rules) These rules have no status condition, and the guard now runs on 200 bodies. A false positive on a seed makes the whole audit blocked with no score and exit 3, which is much heavier than the old warning. Consider gating the text-based ones (Sucuri, Imperva incident line) on a refusal status or smallerThan(...), like the other rules. A page quoting a block-page title, such as a security blog, is the realistic case.
  • (low) packages/crawler/src/fetcher.ts (inspectWafBlock) Add one test showing a plain 404 with Server: cloudflare and a ray id stays an ordinary 404.
  • (low) packages/waf-detect/src/classify.ts (Radware rule) The comment says the host is "recalled, not seen". An unverified signature that can fail a seed should be demoted to suspect until confirmed on a live response.
  • (low) apps/cli/src/cli/commands/audit.ts:3126 Exit code 3 is new public contract. Confirm a test covers it together with --fail-on (which can set 2 afterwards).
  • (nit) packages/waf-detect/src/providers.ts The CHALLENGE_MARKUP_SIGNATURES type reformat is churn on lines unrelated to the change.

Checklist from AGENTS.md: run the .secrets.baseline scan, bun run scripts/test-suites.ts --check (new test files need suite wiring), and build:css:check plus the REPORT_HTML_VERSION bump since html.tsx changed.

@nc9

nc9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Update-branch (merge of main, rule A check): new head 42c0240 = merge commit with parents dcd5408 (approved head) and 306baaa (main tip). The PR's own non-CHANGELOG patch is unchanged: git patch-id --stable is 7b504803a0071e026e0e5b592115dc7f86dbee93 for both, same files, same +/- lines; the raw diffs differ only in blob index lines and hunk line offsets because main moved. CHANGELOG: three Unreleased bullets kept. Pin for merge: 42c0240.

@claude

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Review of #1257 (WAF block detection). I read the waf-detect, crawler/fetcher.ts and crawler.ts changes closely. I skimmed the report, CLI and docs changes and did not run any tests.

The classifier is well built:

  • Each rule needs a provider-specific marker plus a status or body-size shape, so a vendor name alone never counts.
  • Body reads are bounded (SCAN_BYTES), host regexes are anchored, and the probe is lazy and memoised.
  • The blocked / suspect / clear split is a sound design.

Findings:

  • (medium) packages/waf-detect/src/classify.ts (Cloudflare "challenge script" rule): unlike nearly every other rule, it has no status or size guard. /\b_cf_chl_opt\b/, /\b__cf_chl_/ and /cf-browser-verification/i are matched against p.markup() at any status, including 200 on a full-size page. The same applies to the Imperva incident-line, Sucuri and Wordfence-style text rules, which run at any status. A page that legitimately carries one of these strings can fail the seed, and a blocked seed means no score and exit 3. Examples are a Cloudflare dev blog, docs or a changelog quoting _cf_chl_opt in inline code. Please confirm markup excludes visible text and code blocks. Better still, require smallerThan(...) or a refusal status for the Cloudflare markup patterns, and add a 200 full-page negative test.
  • (medium) packages/crawler/src/fetcher.ts (applyWafGuard after readBody()): it now classifies every successful full body, with a 5xx exception only for 503 inside inspectWafBlock. The cost is bounded by the 32 KB scan. The risk is a false positive on a 200 page failing the fetch with no fallback. Consider logging or counting suspect and blocked verdicts on 200 responses so false positives show up in the field.
  • (low) packages/crawler/src/fetcher.ts (statusMayBeChallenge): a 429 now reads up to 64 KB of body before the guard. This is fine, but 429 used to be handled before any body read. Check that a stalled 429 body cannot delay the Retry-After backoff. The catchAll swallows errors, but the read still waits for its deadline.
  • (low) packages/waf-detect/src/classify.ts (Radware rule): the comment admits "Radware's host is recalled, not seen". An unverified signature that can block a seed deserves a note in the docs, or a suspect demotion until it has been seen live.
  • (low) Behaviour change: a 429 from a provider challenge is no longer retried or backed off. This looks intended and is documented. A CHANGELOG ### Changed line would help if there isn't one.
  • (nit) challenge.ts: NOT_DETECTED is a const declared after inspectWafChallengePage, which uses it. This works at runtime but reads oddly, so move it above the function.
  • (nit) providerId: fingerprinted.provider === "DataDome" ? "datadome" : "kasada" compares a display name. Return the id from detectFingerprintedChallenge instead.

Test coverage is good (fixtures per provider, crawler status guards, engine seed-block, report and console). Beyond the 200 negative test above, I'd add a test that a normal 200 page with the Cloudflare JS Detections script, or a Turnstile widget, stays clear.

I found no critical or high issues.

@nc9
nc9 merged commit ecf7184 into main Oct 29, 2026
15 checks passed
@nc9
nc9 deleted the fix/waf-challenge-detection-1253 branch October 29, 2026 05:45
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.

CLI: fail the audit on WAF/bot challenge and block pages (all major perimeter providers), report blocked pages instead of auditing them

1 participant