Skip to content

feat(tech-detect): local scan reads bundles whole up to 8 MB, reports truncation, linear comment scan #1387 - #1392

Closed
nc9 wants to merge 1 commit into
mainfrom
feat/tech-detect-caps-1387
Closed

nc9 wants to merge 1 commit into
mainfrom
feat/tech-detect-caps-1387

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1387.

The local tech scan now reads each first-party bundle whole, says when a cap or the time budget cut it short, and no constant sits below the configured cap.

Limits (local scan / cloud payload)

  • Per bundle: 8 MB / 64 KB ([tech_detect] bundle_bytes sets both; schema max 16 MiB, was 256 KB). TECH_SCRIPT_CONTENT_LIMIT (the hard 256 KB slice in detect.ts) is gone.
  • Per page: 32 MB / 512 KB. Per audit: 64 MB / 1 MB. Page time budget: 30 s / 5 s. MAX_IN_CODE_CANDIDATES 8 to 64. Sampler scan limit 6 MB to 32 MB.
  • The cloud payload keeps its caps (it carries bundle text, sizes bounded by maxBodyBytes); localTechBundleLimits is new, techBundleLimits is unchanged. When every body fits whole, buildTechInputs skips the floor and sampling passes (no second scan of the text).

Truncation report. ReportTechnologies.truncated?: { reasons: ("bundle-bytes" | "page-bytes" | "audit-bytes" | "time-budget")[]; scripts: number }, set by buildTechInputs (byte caps) and detectReportTechnologiesMulti (time budget via onBudgetExceeded). JSON carries it; text, markdown, console and html show a note beside the list through techChangeSummary; llm and xml carry a truncated="..." attribute. Absent when everything was read. Limitation: detectLocalTechnologies still returns null when nothing is detected (so a weak local result never clears synced tech), so a truncated scan with zero items says nothing; and a cloud-detected section does not carry the field.

CPU: the real finding. With the 256 KB slice gone, scanJs (the comment/string scanner under every inCode detector) went quadratic on a body of many /* openers: indexOf("\0") ran to the end of the file for every comment (400 KB of /* took 0.9 s, the existing 3.9 MB adversarial body took 97 s). It now finds the next NUL once. Measured after the fix: the adversarial body detects in 281 ms across all fingerprints (supabase 40, firebase 35, clerk 35 ms); a 5 MB+ hostile body end to end (inputs plus detection) is under a second; 6 scripts x 5 MB benign takes 1.3 s and 157 MB RSS, 60 x 1 MB takes 1.9 s (page cap leaves 30 out, reported as page-bytes), 3 x 8 MB 1.3 s and 254 MB. The #1380 sampler (windows tested against detector patterns) only runs for a body over bundle_bytes; its 5 MB hostile test is unchanged. Detections before/after on the supabase/firebase/clerk real-build fixtures are unchanged (1254 and 1379 suites pass).

Tests: tech-local-caps-1387.test.ts (9: fingerprint 1.5 MB into a 2 MB bundle at the local defaults, 8 MB bundle whole, cloud caps unchanged, bundle/page/audit/time truncation reasons, no field when whole, hostile 5 MB inside the budget), report technologies-truncated-1387.test.ts (5), cli tech-detect-local-limits-1387.test.ts (3), config max (16 MiB), tech-detect (whole body wherever the call sits; 8 MB of /* in linear time). Gates: tech-detect, audit-engine tech, config, report tests (307), tsgo in tech-detect, audit-engine, config, report, core-contracts and apps/cli, cli format:check and lint, make validate, released-changelog guard. The pattern-bounds suite flakes under load (passes alone).

Docs: docs/cloud/technologies.mdx (limits table, truncated, config range). CHANGELOG under Unreleased / Changed. Skill: it needs a change (it still says bundle_bytes is 0 to 262144): private issue squirrelscan/repo#3698 (label skills).

nik

Review round (one squashed commit, no wip commit)

  • scanJs no longer goes quadratic on NUL-split unterminated comments: the next */ is memoised like the next NUL ("/*\0".repeat(n) was 14 s at 1 MB). New tests cover closed, open and NUL-split openers with and without a closer, and NUL-split line comments, at 1 MB and 8 MB, with a tight bound (2 s for the scan, not the page budget); the NUL shape fails at 22 s without the fix.
  • The per-script cap stays for every other caller: DetectOptions.maxScriptChars defaults to TECH_SCRIPT_CONTENT_LIMIT (256 KB) again, so the cloud services and any future gitlink bump keep their cost bound. Only the local scan passes LOCAL_TECH_DETECT_OPTIONS (16 MiB script limit, 30 s page budget). Tested both ways.
  • The cloud section now carries truncated for what the payload caps cut (techInputTruncation), documented; merging the local scan into it is tech-detect: merge the local whole-bundle scan into the signed-in cloud technologies section #1406 (not in this PR).
  • sentry no longer fires on supabase-js (it quotes Sentry.init() in prose at 226 KB): the pattern is /\[Sentry\]|Sentry\.init\(\s*\{/; a built supabase-js bundle is a negative test, and real init calls and the SDK log prefix still detect.
  • Docs: the effective ceiling is the crawl's 5 MB script fetch and its first 10 to 50 scripts (not an 8 MB detection cap); the fetch cap and nothing-detected cases are tech-detect: count scripts dropped by the 5 MB fetch cap and the script limit, and show truncation when nothing was detected #1408. truncated and source are in output.mdx; meta.schemaVersion is 1.3 (it will conflict with feat(report): --include-pages rows carry finalUrl and outcome #1260 #1397's 1.2 line in limits.ts and the e2e/report tests: whichever merges second takes 1.3).
  • Private: squirrelscan/repo#3697 (publish schema keeps truncated/source, accepts 1.2 and 1.3), #3698 (skill text).

… truncation, linear comment scan, per-script cap kept for other callers #1387

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

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@nc9 nc9 closed this Oct 31, 2026
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 reads at most 256 KB per bundle (plus 24 KB samples), 5 s per page, 8 candidates: large app bundles hide technologies

1 participant