Repository navigation
feat(report): disclose a refused off-site seed redirect in every renderer - #189
Merged
Merged
Conversation
3 tasks
…erer When a seed URL redirects off its own registrable domain the crawler refuses the redirect and pins the crawl to the seed, recording where it pointed in report.finalUrl. Nothing read that field, so a report of such a site read as a clean audit of a URL nobody requested. - coverage.ts: seedRedirect()/seedRedirectLine() alongside the other one-line disclosures. Fires only when finalUrl is present, non-blank and different from baseUrl, so no report without one changes at all. - html/markdown/text/llm render it. HTML puts it with the scan-scope lines and deliberately does NOT link it: the point is that we did not go there. llm also emits <seed-redirect final-url=... followed="false"> so an agent cannot read the scores as being about the URL it handed us. - finalUrl is a string the AUDITED SITE chose. It is normalized once (drop whitespace and C0/DEL, which no real URL carries and which a hostile Location keeps because z.string().url() stores the original string) and then escaped per format: React text child, a new escapeMarkdownInline, escapeXml, stripControlChars. - REPORT_HTML_VERSION 12 -> 13 so already-published reports pick the line up on next view via the versioned R2 key. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
feat/1657-seed-redirect-line
branch
from
September 1, 2026 23:19
48e54d2 to
568b87c
Compare
… an unparseable target Three acceptance findings on #189. Renderers: json, xml and the CLI console renderer had no disclosure at all, so `--format json`, `--format xml` and the DEFAULT terminal output carried neither the refused target nor any sign a redirect happened. json gets `meta.seedRedirect` next to the `baseUrl` it qualifies, xml a `<seed-redirect>` element beside `<site>`, console a line under the header — and in the failed/blocked branch too, which returns early and is the likeliest way a refused seed redirect ends with nothing to audit. Unparseable targets: the non-parsing fallback stripped C0/DEL/whitespace but kept the C1 controls (0x9b is an 8-bit CSI a terminal acts on, and text/console output reaches one live) and the bidi overrides. Rather than widen the denylist, `canonicalizeReportUrl` now refuses anything the WHATWG parser does not return as http(s): `SeedRedirect.finalUrl` is `string | null` and the note falls back to fixed text. The only producer resolves `Location` against an absolute http(s) seed, so a value that does not parse is already off the legitimate path and has no shape worth preserving — and refusing is an allowlist that cannot go stale as Unicode adds format characters. The disclosure, which is the load-bearing half, still fires. `dropNonUrlChars` (now only `baseUrl`) drops C1 and the invisible-format/bidi ranges too. Blankness is "nothing but ordinary whitespace", not `trim()`: U+FEFF is in JavaScript's whitespace set, and reading a BOM-only value as an empty field would hand hostile input the silence this disclosure exists to prevent. Round trip: slim JSON now carries the redirect through `convertSlimReport`, so exporting and re-rendering no longer turns a redirected seed back into what reads as a clean audit. A withheld target has no URL to restore and comes back as `WITHHELD_SEED_REDIRECT_TARGET`, which is re-refused into the same disclosure. The file is user-supplied, so a `finalUrl` that is not a string takes the same path instead of reaching a renderer. Tests: no-redirect renderings are pinned by full-output byte equality (every suppression case is byte-identical to the field being absent, and a redirect is proven to be one contiguous insertion and nothing else) rather than by the absence of a phrase; default-port and Unicode-vs-punycode IDN equivalence suppression cases; the llm and xml documents are XMLValidator-validated and parsed rather than string-matched; the `not-a-url<CSI>2J<RLO>txt` repro is asserted across all six renderers plus the console. Signed-off-by: Nik Cubrilovic <[email protected]>
…cludes CodeQL's js/incomplete-url-substring-sanitization reads a URL literal passed to `String.prototype.includes` as a host check. These assertions are the opposite: they ask whether a URL appears in a whole rendered document. Count occurrences instead, which also tightens the renderer sweep from "discloses" to "discloses exactly once"; the console test locates the header line by the score rather than by the base URL. 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.
What
When a seed URL redirects off its own registrable domain, the crawler refuses the redirect and pins the crawl to the seed, recording where it pointed in
report.finalUrl. Nothing read that field, so a report of such a site read as a clean audit of a URL nobody requested: correct scores, correctbaseUrl, and no sign anywhere that a redirect happened or where it went.packages/report/src/coverage.ts:seedRedirect()/seedRedirectLine()alongside the other one-line disclosures (scanScopeLine,coverageLine,fetchFallbacksLine). Fires only whenfinalUrlis present, non-blank and not an equivalent spelling ofbaseUrl, so no report without one changes at all.html / markdown / text / llm all render it. HTML puts it with the scan-scope lines and deliberately does not link it: the point of the line is that we did not go there.
llmalso emits<seed-redirect final-url="…" followed="false">so an agent cannot read the scores as being about the URL it handed us.REPORT_HTML_VERSION12 → 13. The API folds this into the cached-report R2 key, so already-published reports pick the line up on next view instead of serving pre-change HTML forever.Handling the site-controlled URL
finalUrlis whateverLocationthe audited site sent, so it is treated as hostile:new URL(v).hreffor http/https). That drops tab/CR/LF, IDNA-encodes a Unicode hostname (a Cyrillic homograph shows asxn--xample-2of.com), and percent-encodes every non-ASCII code point and C0 control in the path/query/fragment, so an invisible bidi override renders as a visible%E2%80%AErather than silently reversing how the rest of the URL reads. A value that does not parse as an http(s) URL falls back to dropping whitespace, C0/DEL and the code points XML forbids, so the disclosure still happens rather than being swallowed.escapeMarkdownInline(markdown),escapeXmlon both the attribute and the text (llm),stripControlChars(text).Two details worth a reviewer's eye:
>blockquote. A blockquote there is a live bug: CommonMark lazy continuation pulls every following non-blank line into it, so scan scope, coverage, fallbacks and the version all end up inside the warning. Verified against remark-gfm. (The existingfullScanHintline above has the same shape and the same problem for the two lines below it: filed separately, not touched here.)escapeMarkdownInlineescapes&(so‮cannot be decoded back into the override canonicalization just encoded away) but not the scheme colon. GFM autolinks a barehttps://…and a backslash before the colon does not stop it (verified against remark-gfm), so escaping it would only make the raw document uglier. An autolink literal is limited to http/https/www/mailto, so it cannot produce ajavascript:link, and the URL is shown in full either way.Test
packages/report/tests/seed-redirect.test.ts— 20 tests: present / absent / equivalent-spelling / blank / no-baseUrl; control characters, bidi override, zero-width space and a homograph host through the canonicalizer; the non-URL fallback; every renderer with and without the field; markdown block boundary (no blockquote, the metadata below stays its own content); markdown link/image/code-span/emphasis/entity escaping; XML attribute-quote escaping via the fallback path; and no renderer letting a newline start a line of its own.cd packages/report && bun test→ 276 pass / 0 failbun run typecheck(all workspaces) → cleanbun run format:check/bun run lint→ cleanbun test(CLI suite) → 4827 pass / 2 fail, both flakes under full-suite load (report-stream-v2-goldenandauth-session-status); each passes on its own both with and without this change.Related
Surfacing half of squirrelscan/repo#1657. The private side (the API's own markdown template and the MCP
get_reportsummary) is a companion PR there; this is the shared renderer half, and the private repo picks it up with a gitlink bump after this merges.Review round 2 (efc0253)
Three acceptance findings, all addressed.
1. json, xml and the console had no disclosure (medium)
--format json,--format xmland the default terminal output carried neither the refused target nor any sign a redirect had happened. Now wired:meta.seedRedirect { finalUrl, followed: false, note }, placed next to themeta.baseUrlit qualifies so a consumer reading the graded URL sees the contradiction in the same object.<seed-redirect followed="false">element beside<site>, with<final-url>and<note>children (child elements rather than attributes, matching how<site>carries its own URL).Both machine formats carry the same canonical URL the prose renderers print.
2. The fallback preserved C1 and bidi controls (medium) — decided: reject, not encode
dropNonUrlCharsstripped C0/DEL/whitespace/XML-noncharacters but kept U+009B (an 8-bit CSI, which a terminal acts on exactly likeESC[, and text/console output reaches a live terminal) and U+202E and friends.canonicalizeReportUrlnow refuses anything the WHATWG parser does not hand back as http(s), rather than sanitizing it.SeedRedirect.finalUrlisstring | null, and the note becomes fixed text: "Seed redirected off-site and was not followed. The redirect target was not a valid URL and is withheld. This audit graded X."Why reject:
Locationheader against an absolute http(s) seed and stores an absolute URL. A value that does not parse is already off the legitimate path — it is corrupt or injected, and there is no shape worth preserving.Secondary hardening from the same finding:
dropNonUrlChars(now onlybaseUrl, which is not canonicalized) also drops C1 and the invisible-format/bidi ranges: U+00AD, U+061C, U+200B–200F, U+202A–202E, U+2060–206F, U+FEFF.trim(): U+FEFF is in JavaScript's whitespace set, sotrim()would read a BOM-only value as an empty field — handing an unprintable value exactly the silence this disclosure exists to prevent. A no-break space still counts as blank, because it really is a space.3. Tests
soleInsertionproves the two outputs differ by exactly one contiguous insertion and reconstructs the no-redirect output from it, so everything outside the disclosure is provably unchanged.https://example.com:443/,http://example.com:80/, and Unicode-vs-punycode (https://例え.jpvshttps://xn--r8jz45g.jp/) in both directions.XMLValidator.validate()first (the parser alone is lenient about mismatched tags and stray roots), thenXMLParser, then assertions on the tree.fast-xml-parseradded as a devDependency ofpackages/report; it was already a pinned root override at 5.10.1.not-a-url<CSI>2J<RLO>txtrepro is asserted across all six renderers plus the console: the disclosure appears, and no byte of the stored value survives in any spelling (raw, stripped, or percent-encoded).Also found and fixed while here
Adding
meta.seedRedirectto slim JSON exposed a round-trip hole:convertSlimReportdid not restore it, so--format jsonfollowed by a re-render silently turned a report about a redirected seed back into what reads as a clean audit. It now restoresfinalUrl. A withheld target has no URL to restore and comes back asWITHHELD_SEED_REDIRECT_TARGET, whichseedRedirectre-refuses into the identical withheld disclosure — so the disclosure survives precisely in the case where the stored value was hostile enough to be refused in the first place. The JSON file is user-supplied, so afinalUrlthat is not a string takes the same path rather than reaching a renderer.Known and deliberate
The markdown line still GFM-autolinks the target, where HTML deliberately does not link it. Left as-is: it is base-commit behaviour already documented above, only canonical http(s) targets ever reach the note (so an autolink literal cannot produce a
javascript:link), and the URL is shown in full either way. The clean fix — a code span — would require markdown to compose its own sentence from the structured fields, breaking the invariant that every format prints one identical note.Test evidence
packages/report→ 298 pass / 0 failapps/cli→ 1898 pass / 1 skip / 0 failbun run typecheck(all workspaces),format:check,lint,notices:check→ cleandetect-secrets-hook --baseline .secrets.baselineovergit ls-files→ clean, baseline unchanged (html.tsxuntouched, so no line-number shift)CodeQL (860e256)
The first push tripped
js/incomplete-url-substring-sanitizationon a test assertion:output.includes("https://other.example/landing"). The rule matches a URL-shaped literal handed toincludesregardless of what the haystack is, and here the haystack is a whole rendered report, not a URL. Rewritten to count occurrences viasplit(), which the rule does not match and which tightens the renderer sweep from "discloses" to "discloses exactly once". The console test now locates the header line by the score rather than by the base URL.