Skip to content

feat(cli): audit where a start URL redirects, with consent for another site (#1281) - #1282

Merged
nc9 merged 6 commits into
mainfrom
feat/start-redirects-1281
Oct 29, 2026
Merged

nc9 merged 6 commits into
mainfrom
feat/start-redirects-1281

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1281 (does not close it: the cloud half below is a private follow-up).

squirrel audit bit.ly/abc used to score the shortener. The start URL's redirect chain is now resolved before anything is named, estimated or crawled, and the destination is the audit target.

Behaviour

  • Same site (http to https, apex to www, a path): followed silently, no record in the report.
  • Another registrable domain or port: needs consent. TTY prompt per the issue (bit.ly/x redirects to https://example.com/pricing. Audit example.com instead? [Y/n]). Non-interactive: --follow-redirect or [crawler] follow_redirect = true (--no-follow-redirect overrides the config). Otherwise nothing is crawled or scored: exit 4, status redirected, a report naming the final URL, the chain and the re-run command, in console/text/markdown/llm/xml/json.
  • -y is not an input to the decision (pinned by tests/cli/audit-start-redirect-e2e.test.ts and a wiring test).
  • Loop, more than 5 hops, or a hop refused by the egress guard: never followed, exit 4 with the chain so far (reason: loop, too-many, refused).
  • One request per hop through the existing egress guard (egressGuardedSend, no new guard). A public start URL may not redirect into a private/link-local/metadata address; a local start URL may redirect around the local network, never to metadata. Resolved under --offline too (the one request per hop the issue allows); the destination is then audited offline.
  • Project name, credit estimate, crawl scope and the report's baseUrl are the destination's. A followed redirect is recorded as originalUrl + redirectChain (JSON meta, scan notes in text/markdown/html/console, <start-redirect> in llm/xml), persisted in the scan scope so squirrel report rebuilds keep it, and carried through slim-JSON round trips (bounded, canonicalised).
  • Local MCP audit_website: confirmation_required (reason: "redirect") with the destination until called with followRedirect: true (or the config key). confirm: true does not do it.
  • The local store check still runs before any request (audit reports success with 0 pages when the content store cannot be opened #403), then again for the destination's project.

Contracts for the private half (cloud register/run, hosted MCP, website alias)

All in @squirrelscan/core-contracts/seed-redirect (leaf module, one in-package import) unless noted:

  • MAX_SEED_REDIRECT_HOPS = 5, EXIT_CODE_REDIRECTED = 4
  • SeedRedirectHop { url, status }, SeedRedirectResolution { kind: none | same-site | cross-domain | loop | too-many | refused, originalUrl, finalUrl, chain, refusal? }
  • SeedRedirectRecord { originalUrl, redirectChain }: what a followed run carries; cloud: website row = final domain, originalUrl stored as the alias
  • SeedRedirectedOutcome { status: "redirected", reason, originalUrl, finalUrl, redirectChain, rerunCommand, message } and redirectedOutcome(resolution): the answer for a run that was stopped (hosted MCP: confirmation_required for cross-domain, redirected for the rest)
  • AuditReport.originalUrl? / redirectChain?, ScanScope.startRedirect?; chain = every URL requested in order with the status each answered, last entry is the destination
  • Resolver: resolveStartRedirect(url, { transport?, policy?, pin?, userAgent?, timeoutMs?, maxHops? }) from @squirrelscan/crawler/seed-redirect; isSameSite now exported from @squirrelscan/crawler/frontier
  • Renderers: renderRedirectedOutcome(outcome, format), followedStartRedirect(report), startRedirectLine(report) from @squirrelscan/report
  • Config: [crawler] follow_redirect?: boolean. The cloud request should carry follow_redirect (boolean) next to the url; the API resolves with the same function server-side.

Docs, completions, changelog

docs/cli/audit.mdx (flag rows, new "Start URLs that redirect" section, exit code 4), docs/cli/mcp.mdx, docs/configuration/crawler.mdx, docs/configuration/output.mdx, bash/zsh/fish completions, CHANGELOG bullet under ## [Unreleased]. make validate in docs/ passes.

Agent skill

The agent skill needs a change: an agent now meets exit 4 and a redirected report, and must not add --follow-redirect without the user confirming the destination (it is the redirector's choice, not the user's). Private issue squirrelscan/repo#3659 (label skills, with acceptance criteria) tracks it.

Verified

  • per-app tsgo --noEmit (cli, core-contracts, crawler, report, config), bun run lint, format:check
  • tests by path: resolver unit tests (chain, same-site http->https->www, loop, 6 hops, private IP / metadata / non-http refused, local start, unreachable destination), decision + prompt tests, report renderers (hostile URLs neutralised), slim JSON round trip, MCP tool, and an end-to-end subprocess test against local fixtures (localhost vs 127.0.0.1: -y alone exits 4 and the destination is asked once and never crawled; --follow-redirect and the config key audit it; same-site is silent)
  • the compiled binary against a fixture server: exit 4 text output, --follow-redirect JSON report with meta.originalUrl/redirectChain, squirrel report rebuild keeps the note, redirect to 169.254.169.254 refused with exit 4, real TTY (pty) prompt shows the issue's copy and declining exits 4
  • updated the squirrel audit --offline: hold the crawl's own redirects and off-site sitemaps to the audited site #819 offline wiring test (a start redirect now resolves once and stops with exit 4 without consent) and its online control (needs --follow-redirect)

Not covered

  • Cloud/API/dashboard half (website alias, register with follow_redirect, hosted MCP handshake): private PR.
  • squirrel crawl, squirrel analyze and MCP quick_check still take the URL as given (not in the issue's scope).
  • Client-side redirects (meta refresh, script) on the start URL are not part of the chain; the crawler's existing handling applies.
  • No test of the interactive accept path end to end (the project-name prompt for a local destination follows it in a pty); accept is covered by unit test with an injected prompt.

Review round 1 (head after this push)

  • Chain URLs are printed and recorded as scheme, host, port and path only (no userinfo, query or fragment) in every output, prompt and the MCP payload; the re-run command uses the URL the user typed.
  • A chain that detours through another domain and back is cross-domain.
  • Markup characters in site-chosen URLs are percent-encoded; the html outcome is real escaped HTML; a refused non-http hop is named by scheme only.
  • PTY: accept exits 0, decline exits 4 (child exit codes read via a pty helper).

Private follow-up still open for #1281

Website created under the final domain with the original URL as an alias, cloud register/run follow_redirect, and the hosted MCP confirmation_required handshake.

nc9 added 6 commits October 30, 2026 07:20
…r site (#1281)

Resolve the start URL's redirect chain before anything is named, estimated or
crawled: one request per hop through the egress guard, capped at 5 hops. A
same-site redirect is followed silently. A cross-domain one needs consent: a TTY
prompt, --follow-redirect or [crawler] follow_redirect; -y does not imply it.
Otherwise exit 4 with a redirected report naming the destination, the chain and
the re-run command. Loops, long chains and refused hops are never followed.

A followed redirect is recorded as originalUrl and redirectChain in every output
format and survives a report rebuild. The MCP audit_website tool answers
confirmation_required with the destination until followRedirect: true.

Signed-off-by: Nik Cubrilovic <[email protected]>
…-domain, escape outputs (#1281)

Print and record each chain URL as scheme, host, port and path only; the
re-run command uses the URL the user typed. Classify a chain cross-domain when
any hop leaves the registrable domain. Percent-encode markup characters in
site-chosen URLs, emit real HTML for the html outcome, and name a refused
non-http hop by scheme.

Signed-off-by: Nik Cubrilovic <[email protected]>
…cument the redacted audit target (#1281)

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review October 29, 2026 21:48
@nc9
nc9 merged commit f3f8e63 into main Oct 29, 2026
17 checks passed
@nc9
nc9 deleted the feat/start-redirects-1281 branch October 29, 2026 21:49
@claude

claude Bot commented Oct 29, 2026

Copy link
Copy Markdown

Reviewed the resolver (packages/crawler/src/seed-redirect.ts) and the contracts in packages/core-contracts/src/seed-redirect.ts. I did not read the whole 3k-line diff, and I did not run the tests or CI.

  • (medium) packages/crawler/src/seed-redirect.ts (done()) sets finalUrl\: redactUrl(finalUrl), and redactUrl strips the query and fragment. apps/cli/src/cli/start-redirect.ts:52 and :57 then use resolution.finalUrl as the audit target. A shortener that redirects to https://example.com/page?id=5 or a ?lang=fr variant is audited as https://example.com/page. That is a different page, or a 404 or a login wall. The too-many re-run command is stripped the same way. Redaction is right for printed output, but the audit target should keep the real URL. For example, carry an unredacted finalUrl internally and redact only when rendering. Alternatively, document the query-stripping and add a test that pins it.
  • (low) resolveStartRedirect: when a later hop fails on the network, done(current) is called with the destination that never answered. If an earlier hop already crossed domains, this can report cross-domain with a chain whose last entry is a 3xx rather than a destination answer. This contradicts the doc comment on SeedRedirectResolution.chain. Worth a test for the intended behaviour.
  • (nit) The total budget is 30s and the per-hop timeout is 10s. When the budget runs out, done(current) returns without marking the chain as truncated, so a slow chain looks like it ended normally. Consider a distinct kind or a note.

I found no security problems in what I read. Every hop goes through the existing egress guard, only http and https are followed, and Location URLs are redacted before they are printed.

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