Repository navigation
fix(report): stop the full-scan hint swallowing the metadata below it - #193
Merged
Merged
Conversation
The #1180 full-scan hint was emitted as `> ${hint}` in the middle of the report's metadata run. A CommonMark block quote can interrupt an open paragraph, so the quote opened there and lazy continuation pulled every following non-blank line inside it: a partial scan rendered its render-block recovery note and its generator version as part of the warning. The hint becomes a plain line, matching the seed-redirect disclosure directly above it (which carries a comment saying it is plain for exactly this reason) and matching the text and HTML renderers, which have always rendered this hint as a plain line. Markdown was the odd one out. The one other blockquote in this renderer, the rule description, is already terminated by a blank line; a test now pins that too. Tests assert the block boundary, not just that the hint text is present — the broken output contained every one of those strings. A small CommonMark lazy-continuation scanner reports which lines a parser would place inside a quote, and both swallowed lines are asserted to be outside one. Closes #190 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Sep 2, 2026
Round-2 review findings, both reproduced with an instrumented probe before being fixed and re-probed after. release() only disarmed the timer. Every path that releases WITHOUT a body read therefore left the stalled body and its socket parked for the life of the process -- the exact leak class this change exists to kill. Two such paths: a terminal 403/429/5xx that fails applyStatusGuards before any read, and a redirect hop still held when the NEXT request fails (the loop drops a superseded hop only once a newer response arrives). Probe on both: `server saw cancel: false`. release() now aborts as well. That is safe unconditionally because release runs only as the effect leaves: on the success path the stream is already drained and the abort is a no-op. The 503 challenge read swallowed every failure via orElseSucceed, including the timeout this PR newly maps, so a stalled 503 body came back as the generic `network: Server error: 503` -- blaming the origin for our own deadline. It now re-fails on a timeout and still degrades every other read failure to "no body", so the guard can classify the 503 from headers alone. Three tests added, each verified to fail against the previous commit: two use a server-side `req.signal` observer to prove the connection is actually cancelled (terminal status, failed hop), and one asserts the stalled-503 classification is `timeout`. Rebased onto main after #193 merged. Refs squirrelscan/repo#1729 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Sep 2, 2026
#191) * fix(audit-engine): keep the fetch deadline armed through the body read Five fetchers cleared their AbortController timer where the fetch resolved, i.e. when the response HEADERS landed, leaving the body read with no time bound. readBodyCapped and response.text() cap BYTES, not seconds, so an origin that answers 200 and then trickles or stalls its body parked the caller forever. Same class as #187 fixed in the crawler; these are the stragglers. clearTimeout moves into a finally that wraps the body read. The script fetchers split their retry loop out of the attempt so each retry arms a fresh deadline instead of inheriting a spent one. The CLI forks are the live path for the `squirrel` binary (apps/cli imports its own crawler/, not the engine package), so fixing only the package would have left users hanging. Sites fixed: - packages/audit-engine/src/script-fetcher.ts (body read) - packages/audit-engine/src/external-checker.ts (WAF 403 body read) - apps/cli/src/crawler/script-fetcher.ts (fork) - apps/cli/src/crawler/external-checker.ts (fork) - apps/cli/src/crawl/sitemaps.ts (text read ran after the timer cleared) Scripts and external links are fetched during rules enrichment, after the crawl, so the failure mode was a post-crawl hang: an audit with all its pages that never finishes. The sitemap read hangs the crawl preamble. Regression tests serve headers then hold the body stream open forever; all five hang without the fix and time out at the deadline with it. The engine tests are added to test:golden so CI actually runs them. Refs squirrelscan/repo#1729 Signed-off-by: Nik Cubrilovic <[email protected]> * fix(cli): await and catch the discarded sitemap body cancel A bare `void body.cancel()` leaves a rejected cancel unhandled — an already-errored stream rejects, and an unhandled rejection is a worse outcome than an undrained socket. Signed-off-by: Nik Cubrilovic <[email protected]> * fix(crawler): hold the fetch deadline through fetchPageStandard's body read Acceptance-review follow-ups on the #1729 deadline sweep. packages/crawler/src/fetcher.ts had the same clear-at-headers bug wearing a try/finally that looks correct: requestWithTiming cleared its timer in a finally that closes at the fetch, then returned the Response for fetchPageStandard to read much later. The same finally also removed the fiber-interrupt bridge, so the watchdog's abort never reached the reader -- readBodyCapped stayed parked on reader.read() for the life of the process, holding the socket and its buffered chunks. Not an unbounded hang: crawler.ts's per-URL watchdog (>=120s) is the backstop. But a stalled page burned the whole watchdog instead of timeoutMs. requestWithTiming now returns a TimedResponse whose deadline stays armed; the caller owns it across the redirect loop and the body read, drops superseded hops (which the loop never did, leaking their sockets), and Effect.ensuring releases whatever is still held on every exit -- a try/finally inside Effect.gen would not run on failure. The body read's interrupt bridge now aborts the request rather than only losing a race, and a deadline that fires mid-body reports a timeout, not a parse error. fetchPageStandard is split behind Effect.suspend so the held-response state is per RUN: callers retry this same Effect value. External checker (both copies): a 403 whose body could not be read no longer abandons WAF detection. Detection runs on the response headers, which are evidence in their own right -- most WAFs are identifiable from cf-ray / x-sucuri-id / a provider server value alone. Giving up there reported live, bot-guarded links as broken, and the deadline now makes that read fail more often. Sitemaps: the terminal catchAll carries the failure reason instead of collapsing every non-HTTP failure to "Unexpected error", so a body-read timeout, a connect failure and an HTTP error are distinguishable. Its error-channel value no longer mimics the success shape. Tests: each new case was verified against origin/main -- 4 of 5 engine and 6 of 8 CLI cases fail there, and both crawler stall cases fail, one by hanging and one by observing that the server never saw the client abort. The retry tests now stall attempt 2's body, so they pin that the retry's deadline is fresh AND covers its body; the earlier form passed unfixed. Refs squirrelscan/repo#1729 Signed-off-by: Nik Cubrilovic <[email protected]> * fix(crawler): cancel a held response released without a body read Round-2 review findings, both reproduced with an instrumented probe before being fixed and re-probed after. release() only disarmed the timer. Every path that releases WITHOUT a body read therefore left the stalled body and its socket parked for the life of the process -- the exact leak class this change exists to kill. Two such paths: a terminal 403/429/5xx that fails applyStatusGuards before any read, and a redirect hop still held when the NEXT request fails (the loop drops a superseded hop only once a newer response arrives). Probe on both: `server saw cancel: false`. release() now aborts as well. That is safe unconditionally because release runs only as the effect leaves: on the success path the stream is already drained and the abort is a no-op. The 503 challenge read swallowed every failure via orElseSucceed, including the timeout this PR newly maps, so a stalled 503 body came back as the generic `network: Server error: 503` -- blaming the origin for our own deadline. It now re-fails on a timeout and still degrades every other read failure to "no body", so the guard can classify the 503 from headers alone. Three tests added, each verified to fail against the previous commit: two use a server-side `req.signal` observer to prove the connection is actually cancelled (terminal status, failed hop), and one asserts the stalled-503 classification is `timeout`. Rebased onto main after #193 merged. Refs squirrelscan/repo#1729 Signed-off-by: Nik Cubrilovic <[email protected]> --------- Signed-off-by: Nik Cubrilovic <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #190.
packages/report/src/output/markdown.tsemitted the #1180 full-scan hint as> ${hint}in the middle of the report's metadata run:A CommonMark block quote can interrupt an open paragraph, so the quote opened right there, and lazy continuation pulled every following non-blank line inside it. A report with a partial scan rendered its render-block recovery note and its generator version as part of the warning quote.
Fix
The hint becomes a plain line. That is what the seed-redirect disclosure three lines above it already does, and its comment says why:
It also matches
text.tsandhtml.tsx, which have always rendered this hint as a plain line. Markdown was the odd one out. The alternative in the issue, a blank line after the quote, would split the hard-broken metadata run into three separate paragraphs and diverge from the other renderers, so the plain line wins on both counts.Rendered header block, after:
The other blockquote in this renderer,
> ${rule.description}, is already terminated by a blank line. It was audited and is now pinned by a test so a future edit cannot drop that terminator and start swallowing the solution and check table below it.Tests
packages/report/tests/markdown-blockquote-190.test.tsasserts the block boundary, not string presence — the broken output contained every one of those strings too. A small scanner applies the two CommonMark rules this bug turns on (a>opens a quote even mid-paragraph; every following non-blank line is a lazy continuation until a blank line closes it) and reports which lines a parser would place inside a quote. The fetch-fallbacks note and the**Version:**line are asserted to be outside one, and the metadata run is asserted to contain no quote opener at all.Verified by reverting the renderer to
mainand re-running: 2 of the 4 tests fail on the old output.bun testinpackages/report: 302 pass, 0 failbun testinapps/cli: 1898 pass, 0 failbun run test:engine: 63 pass, 0 fail, golden baseline unchanged (pages=518 findings=98221 healthScore=48)bun run typecheck(all workspaces),lint,format:check: cleanMarkdown-only change, no HTML output bytes touched, so
REPORT_HTML_VERSIONis unchanged.