Skip to content

fix(tech-detect): derive search literals for unhinted detectors and share the window budget #1420 - #1433

Closed
nc9 wants to merge 6 commits into
mainfrom
fix/tech-extras-budget-1420-r2
Closed

nc9 wants to merge 6 commits into
mainfrom
fix/tech-extras-budget-1420-r2

Conversation

@nc9

@nc9 nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #1421 (the original author lane stalled). The cherry-picked commit is f8cfd44 rebased onto v0.0.149; the second commit applies the independent review's required fixes.

Refs #1420

What it does

A bundle bigger than its byte cap is read as its first 16 KB, windows around the literals the detectors look for, and the end of the file, in 24 KB. Detectors with no hand-written hint (Sentry, React, PostHog, Stripe, GA4...) only had whatever the windows left. Now they get a literal derived from their pattern (hint-derive.ts), windows are shared out round-robin (at most 8 qualified windows per hint) and the tail keeps a reserve of min(6 KB, budget / 4).

Review findings fixed

  1. MEDIUM, inCode qualification: a window now qualifies for an inCode detector only when a match starts in code (whole-file string, regex and comment spans), so string mentions no longer count against the 8 windows (a real Firebase/Supabase/Clerk config after 8 or more mentions was lost). Declared hints also get their first 2 windows before any derived hint's first round.
  2. MEDIUM, U+0130: it is folded to I before lower-casing (the only code point whose lower case changes length, checked over all code points), so one dotted capital I no longer disables the case-insensitive literals.
  3. MEDIUM, selectivity: the most selective required run is used, not the longest (punctuation, digits, capitals and underscores score higher), and bare common words (config, init, account, install, window[...) are never a literal. GA4 now uses gtag(, Yandex ym(, MailerLite ml(, AppDynamics adrum-, Swiftype _st(. Measured over 40 built bundles (react, vue, svelte, stripe-js, sentry, posthog, firebase, supabase, clerk, antd, lodash, jquery, jquery-ui, moment, d3, chart.js, zod, core-js...): the most frequent literal now matches 38 times in one bundle (was 610 for config); none over 100.
  4. LOW, escapes: \x, \u, \c, \k, \p and the digits after a digit escape no longer leak their arguments into the literal. New unit cases, and a soundness test that generates strings from every script-content pattern (small generator, no new dependency) and checks the literal occurs in each (over 3,000 matches checked).
  5. Cost: about 20x in the worst case but linear; kept. Bench on the corpus: slowest case 426 ms (PR head: 602 ms).
  6. Copy: CHANGELOG and docs no longer claim every detector has a literal (adobe-analytics has none), no longer say "past the first 256 KB" (sampling starts past the 16 KB head), and say "up to 6 KB (at most a quarter of the budget)". The benefit text is "found past the head in capped scans", with no Sentry-loss claim.

Checks

  • Re-ran the review harness (18 real bundles x cloud, mid, local128k, local1m, whole, plus the synthetic repros): zero detection regressions against both main and PR head, zero new false positives against the whole-body ground truth. Gains over PR head: Firebase after string mentions, PostHog/new-relic with a U+0130, GA4/Yandex/MailerLite after config noise, PostHog in compA.
  • New tests fail on the PR head sampler (7 of 7 new review-fix tests, mutation) and the U+0130 ones also on main's.
  • tsgo in packages/tech-detect and audit-engine, apps/cli format:check and lint, make validate in docs, scripts/check-released-changelog.sh, tech-detect tests (bundle, pattern-bounds, fingerprints, vibe, local-stack, inline script url, extras, soundness), audit-engine tech tests (incl. supabase and real-build), cli tech tests.

No skill change needed (internal sampling, no CLI or output change).

Update 6ff784e: corpus losses vs v0.0.149 (#1433 corpus re-run, 13 sites)

Cause: the tail started after the last kept window, so a loader the window logic had dropped was lost between them (v0.0.149 sent the whole rest of a small script). The window was dropped because the string tracker (a heuristic: a quote in a regex after } or ), a nested template literal) read the loader as part of a long string, which was skipped.

  • The tail is one more span merged with the windows: a rest that fits the room is sent whole, nothing between windows and tail is dropped, overlap is sent once.
  • A hit or cut inside a long string, regex or comment is no longer skipped or jumped past. The cut stays where it is and the segment starts with the characters that opened the span, so the scan of the sent text reads it as the whole file does (a plain cut would make code quoted in an inlined script match as code: harness showed it as false firebase/supabase positives before the opener was added).
  • Tests (fail on efab147): three corpus shapes (26 KB with ttq.load( at 21 KB, 121 KB with fbq( 2 KB from the end, 34 KB with posthog.init at 19 KB) at the cloud and 24 KB caps, rest-whole, tail sent once, and an inlined-script string that must not match.
  • Re-ran the harness (18 bundles x 5 caps + synthetic repros): zero regressions against main and the previous head, zero false positives against the whole-body ground truth; compB's pre-existing PostHog and React misses are now found. A random single-line fuzz with quote traps (3,000 scripts, 20 to 140 KB) loses the loader 0 times (v0.0.149: 1,932, previous head: 1,300).

Update 4447b39: review of 6ff784e (rebased onto v0.0.150 816cf28)

  • A cut inside a long string never lands right after an odd run of backslashes (it backs up one char, so an escaped quote stays escaped), and a long regex literal is skipped as before instead of reopened (a / in a class ended it early). Applies to the tail cut and the hit-inside-long-span window cut. Tests per exploit (escaped ' and backtick at the cut, [x/ in a long regex) fail without the fix.
  • New test: a loader between the last window and the tail is kept (fails if the tail is not merged with the windows). Test helper now joins head and extras with the real NUL separator.
  • Fuzz note: skipping long regex spans loses a loader that sits inside a mis-tracked "regex" (83 of 3,000 fuzz scripts, v0.0.149: 1,932). The 512-hit scan cap and bundle_bytes below about 18 KB behave as before.

Update: round 4 review of 4447b39

  • The opener is a quote and the matcher reads a quote as code, so a cut on the first char after a quote inside a long string completed a quote-initial in-code pattern (Supabase, Firebase, Clerk) with quoted text. Every opener cut (window and tail) now moves on (an escape pair whole, up to 16 starts) until no in-code pattern matches at the opener, and is dropped when none is clean.
  • Tests: every alignment of a quoted Supabase URL, authDomain and publishableKey in ', " and template strings (fail without the fix); tail-cut cases for the escape back-up, a long regex and the opener plus backed-up char at the exact budget edge (each kills its mutant).
  • Cost: a 6.5 MB body of one giant string full of hint literals is sampled in about 100 ms.

Update: round 5 review of 9cb84fc

  • The opener check probed 400 chars, but the in-code patterns have whitespace runs of any length: a config padded past 400 chars after a quote hid from it when the tail was cut on it. settle now probes the text that will be sent (the window end for a window, the end of the file for the tail).
  • Tests: Firebase, Clerk and Supabase text padded with 1 to 800 spaces with the tail cut on it (' and " strings), and the window and tail move on a char instead of being dropped. Mutants killed: old 400-char probe, no check on the tail, one try.
  • Not testable: stepping 1 instead of 2 on a backslash. No shipped in-code pattern can match with a backslash as the second character, so the branch is unreachable today; it stays for a future pattern.

nc9 added a commit that referenced this pull request Oct 31, 2026
…st of a small script whole, merge the tail span #1420

#1433 corpus losses (tiktok, facebook, posthog loaders in small scripts):
- the tail is a span merged with the windows, so nothing between them is dropped and a rest that fits is sent whole
- a hit or cut inside a long string, regex or comment is no longer skipped or jumped past: the cut stays and carries the opener, so the scan reads the span as the whole file does
- tests: three corpus shapes at cloud and 24 KB caps, whole-rest, single tail, and an inlined-script string that must not match

Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added 4 commits November 1, 2026 00:26
…he extras across hints round by round, reserve the tail #1420

Signed-off-by: Nik Cubrilovic <[email protected]>
(cherry picked from commit f8cfd44)
Signed-off-by: Nik Cubrilovic <[email protected]>
… fold U+0130, pick selective literals, skip escape arguments #1420

Review fixes for the derived-literal sampler:
- an inCode detector's window qualifies only when its match starts in code (whole-file string, regex and comment spans), so string mentions no longer use up the 8 windows kept per hint
- declared hints get their first 2 windows before any derived hint's first
- U+0130 is folded to I before lower-casing, so one dotted capital I no longer disables every case-insensitive literal
- the most selective required run is used, not the longest; common words (config, init, account...) are never a literal (GA4 gtag(, Yandex ym(, MailerLite ml()
- \x, \u, \c, \k, \p and digit escapes no longer leak their arguments into the literal
- soundness test generates strings from every pattern and checks the literal against them
- CHANGELOG and docs no longer claim every detector has a literal or a 256 KB start

Signed-off-by: Nik Cubrilovic <[email protected]>
…st of a small script whole, merge the tail span #1420

#1433 corpus losses (tiktok, facebook, posthog loaders in small scripts):
- the tail is a span merged with the windows, so nothing between them is dropped and a rest that fits is sent whole
- a hit or cut inside a long string, regex or comment is no longer skipped or jumped past: the cut stays and carries the opener, so the scan reads the span as the whole file does
- tests: three corpus shapes at cloud and 24 KB caps, whole-rest, single tail, and an inlined-script string that must not match

Signed-off-by: Nik Cubrilovic <[email protected]>
…kip long regex literals instead of reopening them #1420

Review of #1433: the opener put before a cut inside a long string or regex let quoted text read as code (an escaped quote at the cut closed the reopened string; a / inside a regex class ended it). A cut backs up one char after an odd backslash run, and a long regex is skipped as before. Tests per exploit, tail merge test, harness separator fixed to a real NUL.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/tech-extras-budget-1420-r2 branch from 6ff784e to 4447b39 Compare October 31, 2026 13:28
…o in-code pattern #1420

Review of #1433: the opener is a quote and the matcher reads a quote as code, so a cut on the first char after a quote inside a long string completed a quote-initial in-code pattern (Supabase, Firebase, Clerk) with quoted text. Every opener cut (window and tail) now moves on, past an escape pair whole, up to 16 starts, and is dropped when none is clean. Tests: every alignment for a quoted URL, authDomain and publishableKey in ', " and template strings; tail-cut escape, regex and budget cases that kill the surviving mutants.

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

test("a long regex at the tail cut is skipped, not reopened", () => {
const content = withTail(long("/["), `x/${FAKE}${"z".repeat(600)}]/;\n`).replace("var s=/[", "var s=/[");
…400 chars #1420

Review of #1433 round 5: the in-code patterns have whitespace runs of any length, so a config padded past 400 chars after a quote hid from the opener check. settle() now probes up to the window end, or the end of the file for the tail. Tests: whitespace-padded Firebase, Clerk and Supabase text with the tail cut on it (1 to 800 spaces, ' and " strings), window moves on instead of dropping.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9 nc9 mentioned this pull request Oct 31, 2026
nc9 added a commit that referenced this pull request Oct 31, 2026
…st of a small script whole, merge the tail span #1420

#1433 corpus losses (tiktok, facebook, posthog loaders in small scripts):
- the tail is a span merged with the windows, so nothing between them is dropped and a rest that fits is sent whole
- a hit or cut inside a long string, regex or comment is no longer skipped or jumped past: the cut stays and carries the opener, so the scan reads the span as the whole file does
- tests: three corpus shapes at cloud and 24 KB caps, whole-rest, single tail, and an inlined-script string that must not match

Signed-off-by: Nik Cubrilovic <[email protected]>
(cherry picked from commit 5fb1418)
nc9 added a commit that referenced this pull request Oct 31, 2026
…kip long regex literals instead of reopening them #1420

Review of #1433: the opener put before a cut inside a long string or regex let quoted text read as code (an escaped quote at the cut closed the reopened string; a / inside a regex class ended it). A cut backs up one char after an odd backslash run, and a long regex is skipped as before. Tests per exploit, tail merge test, harness separator fixed to a real NUL.

Signed-off-by: Nik Cubrilovic <[email protected]>
(cherry picked from commit 4447b39)
nc9 added a commit that referenced this pull request Oct 31, 2026
…o in-code pattern #1420

Review of #1433: the opener is a quote and the matcher reads a quote as code, so a cut on the first char after a quote inside a long string completed a quote-initial in-code pattern (Supabase, Firebase, Clerk) with quoted text. Every opener cut (window and tail) now moves on, past an escape pair whole, up to 16 starts, and is dropped when none is clean. Tests: every alignment for a quoted URL, authDomain and publishableKey in ', " and template strings; tail-cut escape, regex and budget cases that kill the surviving mutants.

Signed-off-by: Nik Cubrilovic <[email protected]>
(cherry picked from commit 9cb84fc)
nc9 added a commit that referenced this pull request Oct 31, 2026
…400 chars #1420

Review of #1433 round 5: the in-code patterns have whitespace runs of any length, so a config padded past 400 chars after a quote hid from the opener check. settle() now probes up to the window end, or the end of the file for the tail. Tests: whitespace-padded Firebase, Clerk and Supabase text with the tail cut on it (1 to 800 spaces, ' and " strings), window moves on instead of dropping.

Signed-off-by: Nik Cubrilovic <[email protected]>
(cherry picked from commit 33fe7e7)
@nc9

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.151 as 55d8c013 0034317c 6e5c80ec 5b61d57e 3b2c7154 03f67d8c via #1446. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.151. Closing this original.

nik

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.

2 participants