Skip to content

feat(tech-detect): read first-party script bundles, run detection locally from the same bytes #1254 - #1256

Merged
nc9 merged 4 commits into
mainfrom
feat/tech-detect-bundles-1254
Oct 29, 2026
Merged

nc9 merged 4 commits into
mainfrom
feat/tech-detect-bundles-1254

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

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 fix(tech-detect): bound unbounded fingerprint patterns (requirejs 70 s on hostile page) #1244 #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 pages scripts: [] while the cloud sent none; both now fall back to HTML script-URL scanning for a page with no attached body.
  • Offline and signed-out audits already ran local detection (summarize the entity map instead of sampling it #407); this adds the bundle bodies and caps to it. --offline end-to-end test shows technologies with Supabase from a bundle-only SPA.

Tests

  • packages/tech-detect/tests/bundle-content-1254.test.ts: Vite SPA, Next.js chunks (Firebase + Clerk), near-miss negatives, 64 KB cut, hostile 1 MB, budget.
  • packages/audit-engine/tests/tech-bundle-inputs-1254.test.ts: per-bundle, per-page, per-audit caps, once-per-audit attach, UTF-8 byte cut.
  • apps/cli/tests/audit/tech-detect-bundles-1254.test.ts: real squirrel audit --offline against a fixture server; request counts are identical with bundle matching on and off (bundle_bytes = 0).
  • apps/cli/tests/audit/tech-detect-cloud-local-parity-1254.test.ts: cloud payload and local scan detect the same set.
  • Existing tech-detect, audit-engine and CLI tech/cloud tests pass; tsgo --noEmit clean for tech-detect, audit-engine, config, cli; CLI lint and format:check clean; scripts/test-suites.ts --check ok; make validate in docs ok; detect-secrets clean.

Private repo (cloud worker-agent / api)

Cloud payload shape (TechDetectPagePayload) is unchanged, but scripts now carry up to 64 KB bodies (was 16 KB, home page only), on non-home pages too, up to 1 MB per audit. The server must accept that (any per-script or per-page content cap and body limit) and run the same @squirrelscan/tech-detect build. detectTechnologies now also cuts bodies to 64 KB itself. If worker-agent builds its own tech inputs for cloud-run audits, it should call buildTechInputs.

Skill

The squirrelscan agent skill (squirrelscan/skills) needs no change.

nc9 added 4 commits October 29, 2026 13:37
…ed call sites, per-script floor #1254

Signed-off-by: Nik Cubrilovic <[email protected]>
…est_/pk_live_, strict [tech_detect] #1254

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

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Review of #1256 (tech detection reads first-party script bundles). I read buildTechInputs, the cloud.ts changes, the docs and the two CLI tests. I did not run the tests or read the tech-detect package changes.

  • (medium) apps/cli/src/audit/cloud.ts: bundle bodies are now sent to the cloud detection service by default, up to 1 MB per audit, up from 16 KB per inline script. The docs admit that bundles can contain keys, but the only protection is the opt-out bundle_bytes = 0. Consider redacting obvious secrets or high-entropy tokens before upload. Alternatively, send only the extracted windows around vendor markers, or a derived signal. The 16 KB head is sent regardless, so the exposure is wider than the vendor windows. At minimum, say so in the cloud confirm prompt, since runCloudTechDetect already has a confirm callback.
  • (low) packages/audit-engine/src/technologies.ts (buildTechInputs): a body is added to attached as soon as it is planned. A later .slice(0, techDetectMaxScriptsPerPage) can in principle drop it. Bodied URLs are inserted first, so this is probably fine, but a test with more scripts than the cap would pin it down. <script src> values are kept raw (relative) while fetched URLs are absolute, so the same script can occupy two slots before that slice.
  • (low) fitTechDetectPages fallback (cloud.ts): it strips script bodies from the home page only when it is still over budget. It never re-checks that the home payload now fits. If it still doesn't, it is sent oversize, which could 413 and silently lose detection. Consider a final guard or a debug log.
  • (low) Tests: I only saw the end-to-end test and the cloud/local parity test. Unit tests for buildTechInputs in the audit-engine package were not visible to me. They should cover the three-pass budgeting (floor, extras, head), the per-page and per-audit caps, bundleBytes = 0, multi-byte UTF-8 truncation, and one-page-only attachment. Please also prove that the e2e test bites by reverting the change.
  • (nit) apps/cli/src/audit/cloud.ts and technologies.ts: the import ordering is odd (buildTechInputs is slotted between other names). Check format:check and lint for the CLI app.

The shared builder for the local and cloud paths is a good design. The changelog and docs are thorough. The new [tech_detect] config is documented, but I did not confirm that the schema and docs-sync tests cover it.

@nc9
nc9 merged commit 306baaa into main Oct 29, 2026
16 checks passed
@nc9
nc9 deleted the feat/tech-detect-bundles-1254 branch October 29, 2026 04:00
nc9 added a commit that referenced this pull request Oct 29, 2026
… the change history (#1264)

Refs #1263

The guides said technology detection needs an account and credits. A signed-out or `--offline` audit already scans the stack from the crawled pages, headers and first-party JS bundles (#407, #1256); the cloud adds the change history. Fixed in local-audits-cli, audit-levels, cloud-audits, docs index, cloud index and cloud/technologies. Wording follows cloud/technologies.mdx. Docs only; no CHANGELOG bullet (matches earlier docs-only PRs). The squirrelscan agent skill needs no change.
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 detection: include first-party JS bundle contents, and run tech-detect locally when the cloud service isn't used

1 participant