Skip to content

fix(waf-detect): read vendor cookie names, name a bot vendor over its CDN, stop calling CloudFront AWS WAF #750 - #751

Merged
nc9 merged 2 commits into
mainfrom
perch/waf-cookie-vendors
Oct 13, 2026
Merged

nc9 merged 2 commits into
mainfrom
perch/waf-cookie-vendors

Conversation

@nc9

@nc9 nc9 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Closes #750.

@squirrelscan/waf-detect now names bot-protection vendors more accurately, for the CLI's bot-protection warning, the WAF technology entry and the external link check.

Changes

  • Cookie names. COOKIE_PATTERNS covers the vendors below. Values are never read: cookieNamesFromHeaders keeps names only, via Headers.getSetCookie(). A response that sets only the vendor cookie is fingerprinted.

    • Cloudflare: __cf_bm, cf_clearance, __cflb, _cfuvid
    • DataDome: datadome
    • HUMAN: _px3, _pxvid, _pxhd, ...
    • Kasada: KP_UIDz
    • Akamai Bot Manager: _abck, ak_bmsc, bm_sz, bm_sv
    • Imperva: incap_ses_*, visid_incap_*, nlbi_*, reese84
    • AWS WAF: aws-waf-token

    detectWafFromCookies(names) serves callers that stored names only.

  • Stacked vendors. Headers, cookies and body are all read, and the most specific provider wins (PROVIDER_PRECEDENCE: bot vendors before the CDN they sit behind, Cloudflare last). A DataDome block served through Cloudflare is DataDome.

    • Results gain providers: every provider with a signal, most specific first.
    • utils/cdn.ts reads providers.includes("cloudflare"), so "came through Cloudflare" is unchanged.
  • AWS. AWS WAF is now its x-amzn-waf-action header, its aws-waf-token cookie, its *.token.awswaf.com challenge script, or CloudFront's "Request blocked." error page (a Block action is a plain 403 with no WAF header).

    • Medium confidence for the page, since CloudFront serves the same page for a geo restriction.
    • CloudFront, API Gateway and Lambda headers alone (x-amz-cf-id, x-amzn-requestid, x-amz-apigw-id) no longer count. An S3 AccessDenied 403 on CloudFront is a real missing object, not a WAF.
  • Kasada. The x-kpsdk-* response headers count.

Behaviour changes to know

  • detectWaf(headers, body) now always reads the body when given one. Before, it returned early on any high-confidence header. Only callers that pass a body see a difference, and for them the provider is more specific.
  • A Cloudflare site whose pages carry DataDome's tag or HUMAN's _px* cookies now shows waf-datadome (or waf-perimeterx) instead of waf-cloudflare in the WAF technology entry. Cloudflare still appears as a CDN from tech detection.
  • Inputs built from a header record (recordToHeaders) carry set-cookie as one joined string, so only the first cookie name is read there. That is a gap, not a false positive.

Tests

  • packages/waf-detect/tests/cookies-and-stacking.test.ts:
    • each vendor's cookie alone;
    • names only, never values;
    • DataDome behind Cloudflare by header, cookie or block page;
    • Kasada behind Akamai;
    • CloudFront alone is not AWS WAF;
    • AWS WAF by action header, token host or CloudFront block page;
    • S3 AccessDenied on CloudFront is not a WAF;
    • linear token-host regex;
    • an unknown signature is not detected.
  • Updated apps/cli/tests/utils/waf.test.ts (the AWS cases) and packages/utils/tests/cdn.test.ts (Cloudflare is still the CDN under DataDome).
  • Ran the existing waf, external-check, cloud-fetcher, tech-section and golden suites: all pass.

CHANGELOG entry under Unreleased → Fixed. Docs: no page lists the detection signals (external-links.mdx says "Cloudflare, Akamai, etc."), so no docs change.

Skills: no squirrelscan agent skill change needed.

Pairs with squirrelscan/repo#2790 (Perch records the vendor per host and URL). The private repo picks this up with its next gitlink bump.

… CDN, stop calling CloudFront AWS WAF #750

- Cookie names (values never read) identify Cloudflare, DataDome, HUMAN,
  Kasada, Akamai Bot Manager, Imperva and AWS WAF; a block page that sets only
  the cookie is fingerprinted.
- Every source (headers, cookies, body) is read and the most specific
  provider wins (PROVIDER_PRECEDENCE): DataDome behind Cloudflare is DataDome.
  Results carry `providers`, every provider with a signal; utils/cdn reads it,
  so a DataDome block still came through Cloudflare.
- AWS WAF is its x-amzn-waf-action header, aws-waf-token cookie, token-host
  challenge script, or CloudFront's 'Request blocked' page (a Block action is
  a plain 403); not CloudFront / API Gateway / Lambda headers alone, so an S3
  AccessDenied on CloudFront is not a WAF.
- Kasada's x-kpsdk-* response headers count.

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

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Reviewed the diff: detect.ts, providers.ts, types.ts, the cdn.ts change and the new tests. The design is clean. Signals are merged per source, attribution follows an explicit precedence list, and cookie values are never retained. I did not run the tests, and I only skimmed the other detectWaf callers (external-checker, reachability, technologies).

  • (medium) packages/waf-detect/src/detect.ts:~146 isLikelyWafBlock now returns true for any 403 whose response sets a vendor cookie. Cookies like __cf_bm, _cfuvid, bm_sz, ak_bmsc, _abck and visid_incap_* are set on ordinary 200 and 403 responses from any site using that product, not only on blocks. A genuine "forbidden" 403 on such a site is then reported as bot-blocked in the external link check. Cloudflare's cf-ray already behaved this way, so this widens the existing behaviour to Akamai and Imperva. Consider treating cookie-only evidence as medium confidence, or requiring more than a passive-session cookie before isLikelyWafBlock says true, and add a test for a 403 with only bm_sz.
  • (low) detect.ts detectWaf now always scans the body, where it used to return early on a high-confidence header. That is a small cost for a 10KB slice. The PROVIDER_PRECEDENCE filter also silently drops any provider missing from the list. A test asserting that every WafProvider value appears in PROVIDER_PRECEDENCE would stop that drifting when a provider is added.
  • (low) providers.ts The CloudFront "Request blocked." pattern is correctly marked medium, because geo-restriction pages look the same. Check that consumers of isLikelyWafBlock don't turn that into a hard "blocked by WAF" message.
  • (nit) cookieNamesFromHeaders computes indexOf("=") twice. Store it in a local variable.
  • (nit) providers is now a required field on WafDetectionResult, so it is a type break for any external consumer of the published package. Mention that in the CHANGELOG or version notes.

Test coverage is good: cookie fingerprints, stacking, the AWS cases, a ReDoS timing check and a names-only assertion. The 50ms timing assertion could be flaky on loaded CI, so consider a looser bound.

…a block #750

- isLikelyWafBlock reads headers and body only: Bot Manager, Imperva and
  Cloudflare set their cookies on every response of a protected site, so a
  genuine forbidden 403 there carries them too. Cookie attribution is medium.
- The AWS WAF token-host pattern is anchored at a script src (CodeQL
  js/regex/missing-regexp-anchor; also linear).
- Test that every WafProvider has a place in PROVIDER_PRECEDENCE; looser
  timing bound; single indexOf.

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

nc9 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the review and the CodeQL alert on cc282d0, fixed in 5ec129c:

  • (medium) isLikelyWafBlock treated a vendor cookie as a block. Agreed. Bot Manager, Imperva and Cloudflare set their cookies on every response of a site they protect, a real "forbidden" 403 included. isLikelyWafBlock now reads headers and body only, never cookies. Cookies still attribute a response through detectWaf, now at medium confidence. New test: a 403 that sets only bm_sz, visid_incap_*, __cf_bm or datadome is not a block, and the same 403 with x-datadome is.
  • (CodeQL, js/regex/missing-regexp-anchor) providers.ts:214. The AWS WAF token-host pattern is now anchored at a script src=, the same shape as DataDome's captcha-host pattern. That keeps it linear and stops it matching a host name anywhere in the page.
  • (low) A provider missing from PROVIDER_PRECEDENCE would be dropped silently. Added a test that checks the list against a satisfies Record<WafProvider, true> map, so adding a provider without placing it fails.
  • (low) The CloudFront "Request blocked." page is medium confidence. It is. A geo-restricted 403 is still a deliberate block rather than a broken link, so callers saying "blocked" is right for both.
  • (nit) indexOf("=") computed twice. Fixed.
  • (nit) providers is now a required field, a type break for external consumers. @squirrelscan/waf-detect is "private": true (never published), and the only consumers are in this repo and the private one. I checked both: neither builds a WafDetectionResult literal, so nothing breaks.
  • (nit) The 50 ms timing assertion. Loosened to 250 ms, with a comment. The old unanchored pattern took about 90 ms on that 10 KB sample, and the anchored one takes microseconds.

Tests: waf-detect 85 pass; CLI waf, adapter-waf and cloud-fetcher 82 pass; audit-engine waf, tech, soft-404 and broken-resources suites 46 pass; utils cdn 8 pass.

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Reviewed the diff. The approach is sound: cookie names only, no values; attribution by precedence; providers kept for CDN checks; isLikelyWafBlock ignores cookies. Tests cover the new behaviour well. I read the diff and grepped for other WafDetectionResult consumers; I did not run the test suite.

  • (low) packages/waf-detect/src/providers.ts (CloudFront Request blocked pattern): this is medium confidence and also matches a CloudFront geo-restriction page. isLikelyWafBlock ignores confidence, so a geo-blocked 403 on an external link is now treated as bot-blocked. This is probably fine for link checking, but it is worth a comment or a test pinning the intent.
  • (low) packages/waf-detect/src/detect.ts (attribute): a provider missing from PROVIDER_PRECEDENCE is silently dropped, which gives detected: true with provider: null. It is exhaustive today. A test asserting that every WafProvider value appears in the list would stop a future provider from regressing silently.
  • (nit) packages/utils/src/waf.ts: the back-compat re-export does not include the new detectWafFromCookies, cookieNamesFromHeaders or PROVIDER_PRECEDENCE. Add them if consumers are meant to reach them through @squirrelscan/utils.
  • (nit) The datadome cookie regex is case-insensitive while the others are case-sensitive. Pick one convention, or comment why.
  • (nit) _cfuvid, __cflb and __cf_bm are set on any Cloudflare-fronted site, not only bot-protected ones. That matches the CDN meaning and the medium confidence, so no change is needed. Keep it in mind if detected is ever read as "bot protection".

@nc9

nc9 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the review on 5ec129c (all checks green). No change pushed, so CI does not run again:

  • (low) A CloudFront geo-restriction 403 now counts as a block. That is intended. A geo-restricted link is a deliberate refusal at the edge, not a missing page, so "blocked" is the right verdict for the external link check. The pattern's comment in providers.ts says it matches both, which is why it is medium confidence.
  • (low) A provider missing from PROVIDER_PRECEDENCE would be dropped silently. Already covered in 5ec129c: tests/cookies-and-stacking.test.ts › "every provider has a place in PROVIDER_PRECEDENCE" checks the list against a satisfies Record<WafProvider, true> map.
  • (nit) The utils/waf.ts re-export. Left alone on purpose. Nothing reaches the new helpers through @squirrelscan/utils, and the re-export is a back-compat shim, not the API.
  • (nit) The datadome cookie regex is case-insensitive. DataDome sets it lowercase. The i is harmless, and the other vendors' names are mixed-case (KP_UIDz), so they stay exact. I'll fold that into any later change to this file.
  • (nit) _cfuvid, __cflb and __cf_bm mean Cloudflare, not bot protection. Agreed. That is why cookies only attribute (at medium) and never count as a block.

@nc9
nc9 merged commit d633839 into main Oct 13, 2026
15 checks passed
@nc9
nc9 deleted the perch/waf-cookie-vendors branch October 13, 2026 20:30
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.

waf-detect: read vendor cookie names, attribute a bot vendor over its CDN, and stop calling CloudFront AWS WAF

2 participants