Skip to content

fix(tech-detect): read a long next/script snippet kept in a Next.js flight text row #1477 - #1480

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/flight-text-rows-1477
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/flight-text-rows-1477

Conversation

@nc9

@nc9 nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1477 (fixes the shape found; the corpus criterion is a run over the stored crawls and is not done here).

Cause found, and the corpus re-detect below confirms it recovers most of the losers. React Flight writes a string of 1 KB or more as its own text row, id:T<hex byte length>,<text>, and the element points at it: ["$","$L2",null,{"id":"analytics","children":"$7"}]. #1437's reader parsed only the line rows and an element's own strings, so a Clarity loader inside a larger inline snippet (a loader beside other trackers in one next/script, or any snippet over 1 KB) had children or __html set to the reference "$7" and its text sat in a row the reader skipped. The standard 400-character Clarity snippet alone is a plain string and was already read (the real-build fixtures pass), which fits only some of the 46 sites; The remaining misses are listed in the corpus line below; the issue stays open for them.

  • flight.ts: the joined text is parsed into rows properly: id:T<hex>, text rows consume exactly that many UTF-8 bytes (newlines and multi-byte characters included) and are kept by id; other rows end at a newline as before. src, string or array children and dangerouslySetInnerHTML.__html that are a "$<id>" reference to a text row are resolved before the script-component test and the read. An array children now counts for the id plus code-token rule.
  • Still not read: prose, links, JSON-LD and any other element's text row (a p pointing at a long text row, an id'd component with prose text, a type="application/ld+json" script, an a href).
  • Tests (flight-script-narrow-1437.test.ts, 44 pass; 4 of the new ones fail on main): children pointing at a text row for an id'd next/script, a strategy, a plain script and array children; __html pointing at a text row; a text row first with newlines and multi-byte characters followed by other rows; a text row split over chunks; the prose and data negatives; hostile text rows (declared length past the data, 50,000 heads) stay under 3 s. The other flight and markup suites pass.
  • Emission is bounded (review round 1): a resolved text is emitted once however many elements point at it, and the total emitted is capped at the decode cap (8 MB), so references x row size can no longer blow up (10,000 elements, or one element with 100,000 "$7" children, pointing at a 1 MB row threw out-of-memory at about 2 MB of HTML before). Tests: 4,000+4,000 elements at one 1 MB row with a Clarity loader inside it and another row with a GTM script still found; 100,000 references from one element; 40 distinct 1 MB rows stay under the cap; declared lengths too large and too small with emoji and CJK never throw and an exact one reads the rows after it (47 tests; the two bound tests fail without the dedupe and cap).
  • Amplification caps (review rounds 1 and 2): a resolved text row is emitted once however many elements point at it, the total emitted is capped at the 8 MB decode cap, and the code-like verdict for a children text is memoised per call (a Map created inside flightLoaderText, not at module level), so thousands of references to one long text row cost one scan, not one each. Tests: 20,000 references to a 70 KB row that looks like code but has no code token finish under 1 s (fail without the memo); 4,000 + 4,000 elements and one element with 100,000 references to a 1 MB row; 40 distinct 1 MB rows under the cap. Measured on a scratch copy: 50,000 references 253 ms (main 238 ms).
  • Corpus re-detect on this head (33 shards, 19,141 sites, synthetic wording): Clarity recovered on 38 of the 47 sites that lost it, no site lost, PostHog, Vue and Square drops unchanged (99.8% of the results identical to v0.0.152); estimated full-corpus Clarity count about 1,320 against 1,328 on v0.0.150. The 9 still missed: 1 real install whose loader sits in a flight prop shape the reader does not take for a script (tech-detect: Clarity loader in a double-escaped flight chunk is missed (#1477 residual) #1487), 5 whose loader lives in a first-party bundle while the page only names the URL in prose (tech-detect: add a Clarity bundle detector for clarity.ms/tag/ in first-party bundles #1488, feat(tech-detect): detect Microsoft Clarity from its loader in a first-party bundle #1488 #1489), 1 with only window.clarity calls, and 2 that only mention Clarity in prose, correctly dropped.
  • Docs sentence (code-like long text in an id'd component is read like a short string; prose is not) and CHANGELOG (Unreleased / Fixed), rebased onto v0.0.153. Synthetic hosts only.

Skill: no change needed.

nik

…ht payload keeps in a text row #1477

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/flight-text-rows-1477 branch from b50e1e5 to 34b50ee Compare November 1, 2026 01:22
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.154 as 0b5d157f 09a0b144 via #1493. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.154. 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.

1 participant