Skip to content

fix(tech-detect): bound unbounded fingerprint patterns (requirejs 70 s on hostile page) #1244 - #1245

Merged
nc9 merged 3 commits into
mainfrom
fix/tech-detect-unbounded-patterns
Oct 29, 2026
Merged

nc9 merged 3 commits into
mainfrom
fix/tech-detect-unbounded-patterns

Conversation

@nc9

@nc9 nc9 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1244.

Detection scans every stored page with every fingerprint, so a pattern with an unbounded run after a repeatable literal is quadratic on a page that repeats the literal and never closes it. requirejs took about 70 s on 1 MB of <script repeats (1 MB flood now 114 ms for the whole fingerprint set).

Beyond requirejs (the issue), a scan of every html and script-url pattern, each run on 100 KB to 200 KB (the test now uses 200 KB with a 250 ms budget) built from its own leading literal, found 14 more that took seconds: bulma, foundation-sites, semantic-ui, materialize-css, animate-css (<link[^>]+href="[^"]*/x.css), plausible and fathom (data-domain=.*plausible), facebook-pixel, rudderstack, didomi, ensighten, yotpo (.* / .+ in URLs), dynatrace-rum ([_a-z0-9]*), userway. All now have bounded windows (200 to 600 chars; the link patterns also require whitespace before href).

Where: data/research-fingerprints.json, the input of scripts/generate-tech-fingerprints.ts, is not in the repo (the last generated.ts change, #872, also edited it by hand), so the fixes are edits to generated.ts and to analytics.ts / ads.ts. Anyone regenerating from an external copy of that data must carry these bounds over.

Test: tests/pattern-bounds.test.ts builds hostile input from every pattern's own leading literal (and each top-level alternative), plus repeated tag openers per fingerprint, with a 250 ms budget; it fails on the old patterns (plausible 758 ms, fathom 1037 ms, ...) and passes now. A second block checks the rewritten patterns still match real markup.

Gates: tech-detect tests by path (52 pass), audit-engine tech tests by path (22 pass), test-suites.ts --check, tsgo clean. Agent skill: no change.

@nc9
nc9 marked this pull request as ready for review October 29, 2026 00:06
@claude

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Reviewed the diff. The pattern bounds look correct, and I found nothing blocking.

  • (low) generated.ts link patterns: <link\b[^>]{0,400}?(?:\s|["'])href="[^"]{0,300}?/x.css is bounded but nested. On input like <link href=" repeated, each start can try about 30 href= anchors, each scanning up to 300 chars. That is bounded, and the 200 KB / 250 ms test covers it, so it is acceptable. If a 1 MB flood is slow later, anchor on href first.
  • (low) The new windows (200 to 600 chars) can cause false negatives, for example plausible or usefathom more than 600 chars after data-domain= / data-site=, or very long CDN URLs. It is unlikely in practice.
  • (nit) The 250 ms wall-clock budget can flake on a loaded CI runner. AGENTS.md prefers asserting an effect, or checking that time grows about 4x when the input is scaled 4x.
  • (nit) literalPrefix in the test splits on | without regard to groups. Prefixes from inside a group only add coverage, but a comment would help.
  • (nit) Requiring \s|["'] before href also stops data-href= from matching. That is a sensible tightening, but worth a line in the PR notes.

Tests, changelog and the generated.ts caveat are well covered. No security or correctness issues found.

@claude

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Review of #1245: no blocking issues. The bounds look correct and each rewrite keeps the original match shape.

  • (low) packages/tech-detect/tests/pattern-bounds.test.ts:14 The PR description says a 250 ms budget, but BUDGET_MS is 400. Align the two. The budget is also wall-clock, so it can flake on a loaded CI runner. The quadratic cases measured in seconds, so there is room to keep it generous.
  • (low) packages/tech-detect/src/fingerprints/ads.ts:47 The script-url pattern for facebook-pixel is now anchored with ^(?:https?:)?\/\/. The old pattern matched connect.facebook.net anywhere in the string. A script URL that is relative, proxied, or has a leading prefix no longer matches. The new html detector covers the markup case. If scripts[].url is always absolute, this is fine. Otherwise consider dropping the ^ and keeping only the .{0,200} bound.
  • (nit) packages/tech-detect/src/fingerprints/generated.ts:2261 requirejs now needs data-main within 400 characters of <script. A script tag with very long preceding attributes would be missed. That is an acceptable tradeoff, and it may be worth a comment.
  • (nit) The PR notes that data/research-fingerprints.json is not in the repo, so a regeneration would silently drop these bounds. Consider a comment next to the edited generated.ts entries. The new test would catch a regression, but a comment would point to the cause sooner.

I did not run the tests. This review is based on reading the diff.

nc9 added 3 commits October 29, 2026 12:11
…atrace window, 200 KB bound test #1244

Signed-off-by: Nik Cubrilovic <[email protected]>
…und budget for CI headroom #1244

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/tech-detect-unbounded-patterns branch from 529e470 to bd74c42 Compare October 29, 2026 01:11
@claude

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Reviewed the diff. The bounds look correct and I found nothing blocking. Every rewritten pattern now has a finite window, so worst-case work per start position is capped. I did not run the tests locally.

  • (low) packages/tech-detect/tests/pattern-bounds.test.ts:15: the PR description says a 250 ms budget, but the code uses BUDGET_MS = 400. Wall-clock assertions over about 3 detectors × 3 separators per fingerprint can flake on a loaded CI runner. Consider making the description match the code, or keeping the margin as is and saying so.
  • (low) generated.ts (bulma, foundation, semantic, materialize, animate): the new pattern requires href=" with double quotes and caps the attribute window at 400 chars before href. Single-quoted href='...' was already unmatched, so that part is unchanged. A <link> with more than 400 chars of attributes before href is now a miss. That is an acceptable trade-off, but a short comment would help. The same applies to requirejs data-main after 400 chars.
  • (low) ads.ts (facebook-pixel): the script-url pattern is now anchored with ^(?:https?:)?//connect.facebook.net/, where the old one matched the host anywhere in the URL. A script URL that goes through a proxy or wrapper no longer matches. I also added a new html detector, which is a small behaviour change beyond bounding. Both are probably fine, but mention them in the PR or CHANGELOG.
  • (nit) The generated.ts edits are hand edits, and the PR notes that research-fingerprints.json is not in the repo. A header comment next to these patterns, or an issue to track carrying the bounds back to the source data, would stop a later regeneration from silently reverting them.

@nc9
nc9 merged commit 8a63f75 into main Oct 29, 2026
15 checks passed
@nc9
nc9 deleted the fix/tech-detect-unbounded-patterns branch October 29, 2026 02:31
nc9 added a commit that referenced this pull request Oct 29, 2026
…ally from the same bytes (#1256)

Closes #1254

## What

- Tech detection reads the first 64 KB of each first-party script bundle, from the bytes the crawl already fetched for the secret rules (`assets.scripts`). No refetch, no extra request.
- Caps: 64 KB per bundle (`[tech_detect] bundle_bytes`, 0 to 262144, 0 = off), 512 KB per page, 1 MB per audit. A bundle body is attached to the first page that references it; later pages list its URL only.
- New `inCode` flag on `script-content` detectors (`packages/tech-detect/src/js-scan.ts`): the match must start in code, not inside a comment or string literal. Used for Supabase (`createClient` on a 20-char `*.supabase.co` ref), Firebase (`authDomain`, `storageBucket` config) and Clerk (`publishableKey`). Placeholder, short-ref, look-alike-host, comment, docs-string and HTML-only cases are negative tests.
- `detectTechnologies` slices every script body to 64 KB and takes a per-page time budget (default 5 s, `onBudgetExceeded`), on top of the #1245 bounded patterns. A 1 MB hostile bundle test asserts it finishes inside the budget.
- One shared builder (`buildTechInputs` in audit-engine, `buildTechPageInputs` in the CLI) feeds both the local scan and the cloud payload, so a signed-in and a signed-out audit read the same bytes. Previously the local scan passed non-home page
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.

tech-detect: RequireJS fingerprint takes about 70 s on a 1 MB page of unclosed <script tags

2 participants