Skip to content

feat(report): disclose a refused off-site seed redirect in every renderer - #189

Merged
nc9 merged 4 commits into
mainfrom
feat/1657-seed-redirect-line
Sep 2, 2026
Merged

nc9 merged 4 commits into
mainfrom
feat/1657-seed-redirect-line

Conversation

@nc9

@nc9 nc9 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

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, correct baseUrl, 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 when finalUrl is present, non-blank and not an equivalent spelling of baseUrl, so no report without one changes at all.

    Seed redirected off-site to <finalUrl>, not followed. This audit graded <baseUrl>.

  • 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. llm also emits <seed-redirect final-url="…" followed="false"> so an agent cannot read the scores as being about the URL it handed us.

  • REPORT_HTML_VERSION 12 → 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

finalUrl is whatever Location the audited site sent, so it is treated as hostile:

  1. Canonicalized once, by re-serializing through the WHATWG URL parser (new URL(v).href for http/https). That drops tab/CR/LF, IDNA-encodes a Unicode hostname (a Cyrillic homograph shows as xn--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%AE rather 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.
  2. Escaped per format: React text child (HTML), a new escapeMarkdownInline (markdown), escapeXml on both the attribute and the text (llm), stripControlChars (text).

Two details worth a reviewer's eye:

  • The markdown line is a plain line, not a > 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 existing fullScanHint line above has the same shape and the same problem for the two lines below it: filed separately, not touched here.)
  • escapeMarkdownInline escapes & (so &#x202E; cannot be decoded back into the override canonicalization just encoded away) but not the scheme colon. GFM autolinks a bare https://… 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 a javascript: 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 fail
  • bun run typecheck (all workspaces) → clean
  • bun run format:check / bun run lint → clean
  • root bun test (CLI suite) → 4827 pass / 2 fail, both flakes under full-suite load (report-stream-v2-golden and auth-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_report summary) 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 xml and the default terminal output carried neither the refused target nor any sign a redirect had happened. Now wired:

  • json — meta.seedRedirect { finalUrl, followed: false, note }, placed next to the meta.baseUrl it qualifies so a consumer reading the graded URL sees the contradiction in the same object.
  • xml — a <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).
  • console — a line under the header, and in the failed/blocked branch, which returns early. A seed that redirects off-site and is refused is one of the likeliest ways to end up with nothing to audit, so that branch needed it most.

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

dropNonUrlChars stripped C0/DEL/whitespace/XML-noncharacters but kept U+009B (an 8-bit CSI, which a terminal acts on exactly like ESC[, and text/console output reaches a live terminal) and U+202E and friends.

canonicalizeReportUrl now refuses anything the WHATWG parser does not hand back as http(s), rather than sanitizing it. SeedRedirect.finalUrl is string | 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:

  1. The only producer of this field resolves a Location header 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.
  2. Encoding means maintaining a denylist of unsafe ranges that has to stay current with Unicode forever. It was already missing two whole classes. Refusing keeps the allowlist the URL parser already implements, and that parser percent-encodes everything non-ASCII on the way out.
  3. The load-bearing half of the disclosure still fires. The user still learns the seed redirected off-site and was not followed; only the target is withheld.

Secondary hardening from the same finding:

  • dropNonUrlChars (now only baseUrl, 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.
  • Blankness is "nothing but ordinary whitespace", not trim(): U+FEFF is in JavaScript's whitespace set, so trim() 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

  • Byte identity, not phrase absence. For all six renderers, every suppression case (absent, blank, whitespace-only, NBSP-only, same-as-baseUrl, trailing-slash, default-port, case-different) renders byte-identical to the field being absent. And when a redirect does fire, soleInsertion proves 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.
  • Default-port and IDN equivalence suppression cases: https://example.com:443/, http://example.com:80/, and Unicode-vs-punycode (https://例え.jp vs https://xn--r8jz45g.jp/) in both directions.
  • The XML formats are parsed, not string-matched — XMLValidator.validate() first (the parser alone is lenient about mismatched tags and stray roots), then XMLParser, then assertions on the tree. fast-xml-parser added as a devDependency of packages/report; it was already a pinned root override at 5.10.1.
  • The not-a-url<CSI>2J<RLO>txt repro 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.seedRedirect to slim JSON exposed a round-trip hole: convertSlimReport did not restore it, so --format json followed by a re-render silently turned a report about a redirected seed back into what reads as a clean audit. It now restores finalUrl. A withheld target has no URL to restore and comes back as WITHHELD_SEED_REDIRECT_TARGET, which seedRedirect re-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 a finalUrl that 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 fail
  • apps/cli → 1898 pass / 1 skip / 0 fail
  • bun run typecheck (all workspaces), format:check, lint, notices:check → clean
  • detect-secrets-hook --baseline .secrets.baseline over git ls-files → clean, baseline unchanged (html.tsx untouched, so no line-number shift)

CodeQL (860e256)

The first push tripped js/incomplete-url-substring-sanitization on a test assertion: output.includes("https://other.example/landing"). The rule matches a URL-shaped literal handed to includes regardless of what the haystack is, and here the haystack is a whole rendered report, not a URL. Rewritten to count occurrences via split(), 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.

…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
nc9 force-pushed the feat/1657-seed-redirect-line branch from 48e54d2 to 568b87c Compare September 1, 2026 23:19
… 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]>
nc9 added 2 commits September 2, 2026 10:26
…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]>
@nc9
nc9 merged commit e0bba55 into main Sep 2, 2026
13 checks passed
@nc9
nc9 deleted the feat/1657-seed-redirect-line branch September 2, 2026 00:51
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