Skip to content

fix(crawler,audit-engine): the --max-duration parse cap judges the decoded page #1497 - #1498

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/parse-cap-decoded-size
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/parse-cap-decoded-size

Conversation

@nc9

@nc9 nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1497.

The --max-duration cap (5 MiB, because a parse cannot be interrupted) compared the recorded sizeBytes, the Content-Length header, which is the encoded size. A gzip response of a few KB that inflates past the cap was parsed in full. Same wire size in three places, all fixed:

  • crawler.ts parse gate, adapter.ts buildSiteContext, and streaming.ts (the pass that counts and lists the pages left out) now use decodedPageBytes(sizeBytes, body) (new, @squirrelscan/utils/bytes): the larger of the recorded size and the body's UTF-8 bytes. Exact (Buffer.byteLength, no allocation), and only evaluated when a cap is set. sizeBytes stays the reported transfer size.
  • Probe (a local server, run before the fix): a gzip body of about 1 KB on the wire inflating to 300 KB, cap 64 KB, was parsed and its links followed.
  • Tests: parse-cap-decoded-size.test.ts (crawler through crawler.start(), 4 tests; the gzip and the multi-byte cases fail on main, the plain-over-cap and under-cap cases pass on both), site-context-parse-cap-1332.test.ts (an inflated page recorded at its encoded size is left unparsed) and streaming-parse-cap-decoded-1332.test.ts (3 tests; the first fails on main: the page is counted in pagesTooLarge and listed). The existing max-duration tests pass. The large-page e2e (audit-max-duration-large-page-1332-e2e) needs a quiet runner: it passes at a load of 11 to 17 with a margin of about 0.5 s at +10 CPU hogs, and timed out at a load of about 50 here with and without this change, so it is not evidence either way.
  • Docs sentence in docs/cli/audit.mdx (the 5 MiB is the decoded size) and CHANGELOG under Unreleased / Fixed. tsgo is clean for the three packages.

Review round 1: boundary tests (a decoded page of exactly the cap parses, one byte more does not) in the crawler gate (plain and gzip), buildSiteContext and the streaming guard, which kill the > to >= mutants at all three sites; multi-byte cases (30,000 three-byte characters, under the cap in characters and over it in bytes) in buildSiteContext and the streaming test. The bytes.ts comments say a response with no Content-Length is sized from its body (so the multi-byte gap before this change was gzip only) and that current Bun counts a lone surrogate as 3 bytes.

Skill: no change needed.

nik

…coded page, not the Content-Length #1497

Signed-off-by: Nik Cubrilovic <[email protected]>
…ts (CodeQL js/incomplete-url-substring-sanitization) #1497

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

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.155 as f13577dc via #1503.

nik

@nc9 nc9 closed this Nov 1, 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.

audit: the --max-duration parse cap compares the encoded size, so a small gzip body that inflates past 5 MiB is parsed

2 participants