Skip to content

fix(waf-detect): a signature counts where it acts, not where a page quotes it #693 - #884

Merged
nc9 merged 1 commit into
mainfrom
fix/693-waf-quoted-signatures
Oct 17, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/693-waf-quoted-signatures

Conversation

@nc9

@nc9 nc9 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Closes #693

What changed

packages/waf-detect/src/views.ts adds signatureViews(html), one linear pass over the 10 KB sample, producing two readings:

  • markup: every tag with its attributes except hyperlinks (<a>, <area>: a link to a provider's script is a mention), plus inline <script> bodies. No text, so &lt;script src="https://js.datadome.co/tags.js"&gt; in a tutorial is not DataDome.
  • text: the HTML minus comments, script and style bodies, and <code>, <kbd>, <samp>, <textarea>, <xmp> elements. Tags are kept, since the wording patterns allow tags between label and id. A bare <pre> stays, because CloudFront's own block page prints "Generated by cloudfront (CloudFront)" in one (existing waf-detect: read vendor cookie names, attribute a bot vendor over its CDN, and stop calling CloudFront AWS WAF #750 test). The <pre><code> that Markdown and syntax highlighters emit is removed by its <code>.

Raw-text and RCDATA elements are skipped as the HTML parser does, and never self-close. Lowercasing is ASCII-only so offsets stay aligned.

Each CONTENT_PATTERNS entry now names its view (Cloudflare and Imperva split into a text entry and a markup entry). The regexes themselves are unchanged. The same views now gate:

  • challengeMarkers: challenge markup per view; challenge text on the text view
  • detectFingerprintedChallenge: DataDome/Kasada 200 interstitials, which use only markup markers

So a quoted signature no longer sets a Cloudflare-served 200 page aside as a challenge either.

Wording in a paragraph

The AC lists "paragraph text". That holds for script and resource signatures. Block-page wording (ray id, reference id, incident line, Sucuri title, CloudFront footer) stays readable in a <p>, because real block pages print it there: <p>Cloudflare Ray ID: <strong>…</strong></p> and Akamai's <P>…edgesuite…</P> are existing positives the AC requires to keep passing. Its quoted form is a code element.

Acceptance criteria

  • A signature only inside <pre><code>/<code>, or (script/resource signatures) in paragraph text, is not attributed: the issue's three pages plus a generated quoted variant of every positive
  • The same signature in a <script src>, an inline script or an <iframe src> is still attributed
  • Every positive in content-signatures.test.ts passes, and quoted variants of each are negatives (50 of the new assertions fail on origin/main's detect.ts)
  • Skill: no change needed.

Also:

  • apps/cli/tests/crawler/cloud-fetcher.test.ts: the render-block fixture had challenge markers as body text. It now carries them where a challenge page does (an element id and a script), and the old text-only form is asserted not a block.
  • Docs: docs/guides/failed-audits.mdx (#waf-challenge) says where signatures count.

Tests: waf-detect 154/154, CLI waf + adapter-waf + cloud-fetcher 82/82, audit-engine soft404/waf-tech 21/21. Typecheck (waf-detect), oxlint on changed files, codex review (2 rounds; P2s on Unicode offsets, raw-text self-closing and the 200-fingerprint path fixed).

…uotes it #693

signatureViews splits the 10 KB sample into markup (tags bar <a>/<area>, inline
script bodies) and text (no comments, script/style bodies or code elements).
Content patterns, challenge markers and the 200-challenge fingerprints each
read their view, so a tutorial or support page quoting a signature is neither
attributed nor a challenge.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/693-waf-quoted-signatures branch from 07bb67a to 6474cf1 Compare October 17, 2026 00:09
@nc9
nc9 marked this pull request as ready for review October 17, 2026 00:09
@claude

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown

Reviewed the diff and read views.ts, challenge.ts and detect.ts in full. I did not run the test suite and did not read the test diff, so my test comments below are limited to what the PR description says. The design is sound: one linear pass, ASCII-only lowercasing so offsets stay aligned, tagEnd extracted and shared, and raw-text elements handled as the HTML parser does. I found nothing that should block merge.

  • (low) packages/waf-detect/src/views.ts:116 An unclosed <code>, <kbd> or <samp> hides the rest of the sample from the text view, because quoteDepth never returns to 0. A real block page with a stray or unbalanced <code> before its Ray ID or incident line would then go undetected, and so would a 200 challenge page that relies on text markers. The HTML parser would close these implicitly at block boundaries. Consider capping the depth, or resetting it on </body> or </p>. A test for the unbalanced case would also help.
  • (low) packages/waf-detect/src/views.ts:103,61 Each < builds a regex and runs /[a-z0-9-]/.test once per character, and /\s/.test in rawTextEnd does the same. It stays linear over a 10–20 KB sample, so it is not a real problem. Hoisting the regexes to module constants and comparing char codes would be cheaper if this ever sits on a hot path.
  • (low) packages/waf-detect/src/views.ts:112 tagEnd treats any quote inside a tag as opening a quoted string. A malformed tag such as <div class="x> swallows the rest of the sample into one tag. That matches what browsers do for attributes, so it is acceptable. Still, add a test showing a signature after a malformed tag is handled the way you intend.
  • (nit) packages/waf-detect/src/views.ts:121 Excluding <a> and <area> from the markup view means <a href=…> wrapping an <img src=<provider pixel>> still counts, but the <a> tag's own attributes do not. This looks intentional. A short comment would make that explicit.
  • (nit) The wording-in-<p> exception is documented in the PR body. Adding it to the views.ts header or the CHANGELOG would keep it from being rediscovered as a bug later.

@nc9
nc9 merged commit 232acea into main Oct 17, 2026
16 checks passed
@nc9
nc9 deleted the fix/693-waf-quoted-signatures branch October 17, 2026 00: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.

waf-detect: a page that quotes a provider's signature in text is still attributed to it

1 participant