Skip to content

fix(crawler,engine,cli): --offline holds every request to the audited site - #1171

Merged
nc9 merged 2 commits into
mainfrom
fix/819-offline-own-site
Oct 27, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/819-offline-own-site

Conversation

@nc9

@nc9 nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Closes #819.

squirrel audit --offline now sends nothing to a host outside the audited site. The site's own hosts are the audited host, its www or apex twin, [project] domains and the subdomains of all of them, one definition (ownSiteHostMatcher, packages/utils/src/own-site.ts) feeding EgressPolicy.allowHost everywhere.

Acceptance criterion Where it is enforced Test
A page redirect to another host is recorded as a redirect and the other host gets no request crawl egress policy (egressFor, ownSiteOnly); seed redirect probe; CLI reachability probe packages/crawler/tests/offline-own-site-819.test.ts, apps/cli/tests/utils/reachability.test.ts, apps/cli/tests/commands/audit-offline-third-party-wiring.test.ts
A sitemap on another host (robots.txt, or a redirect from a sitemap on the site) is not fetched, and the report says skipped, not missing discoverSitemaps + SITEMAP_OFF_SITE_SKIPPED_ERROR; crawl/sitemap-exists and crawl/sitemap-valid crawler test above, packages/rules/tests/sitemap-off-site-skipped-819.test.ts
A first-party asset that redirects to another host is not followed, and reliability/broken-resources reports it as not requested ownSiteEgress.allowHost in the asset phase packages/audit-engine/tests/offline-own-site-819.test.ts
The cloaking probe and the soft-404 confirmation send nothing to another host probeEgress(..., ownSiteOnly) same engine test file
Assets on the www or apex twin or a project domain are checked like the site's own absorbResourceOccurrences(..., isOwnHost) same engine test file
Each case proven by Host header with a second server, with a control where it is requested every test above has a control without the policy
Docs and --offline help text match docs/cli/audit.mdx, rule pages, help and completions make validate

The AI agent access probe and the discovery probes use the crawl's egress policy, so they stay on the site too.

Reviewed with a Sonnet security pass; its findings were fixed here (an own-host sitemap that redirects off-site now reads as skipped, manifests use the shared matcher, project domains with a port, wildcard or Unicode name match). Known and left alone, with reasons:

  • security/http-to-https follows redirect hops through rules/src/links/redirects.ts with no allowHost; its request tool is never injected today (no request is sent), so nothing leaks, but it should be gated if it is ever wired.
  • When the user names a link-local or metadata address as the site itself, the crawl runs with no egress policy by design (the user's choice), so --offline does not restrict that run.
  • The resident runRulesOnStorage path (squirrel analyze, no --offline) does not take ownSiteOnly.

Behaviour note: in an offline audit only, a reference on the www or apex twin or a project domain moves from the third-party pool to the site's own pool. Default audits are unchanged.

Docs: updated (audit command page, sitemap-exists, sitemap-valid, broken-resources). Skill: no change needed.

@claude

claude Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewed the diff, with most attention on packages/utils/src/own-site.ts, the sitemap change and public-egress.ts. I didn't run the tests. The design is sound: one matcher feeds EgressPolicy.allowHost, and the tests pair each refusal case with a control that is requested. No blocking issues.

  • (low) packages/utils/src/own-site.ts: every subdomain of the audited host's apex counts as own-site. Auditing www.example.com allows anything.example.com, and the same holds for [project] domains. That is documented and probably intended. But on a shared-suffix host such as user.github.io or x.vercel.app, the www. twin and apex logic can reach unrelated tenants. This is edge-case and only affects --offline. Consider a one-line note in docs/cli/audit.mdx that own-site includes sibling subdomains.
  • (low) packages/crawler/src/sitemaps.ts: the off-site refusal is recognised by comparing error.message === EGRESS_OFF_SITE_REFUSAL. That depends on a string. A reason or code field on EgressRefusedError would be sturdier than matching message text, though the shared constant limits the drift risk.
  • (nit) own-site.ts: isIpLiteral treats any host containing : as IPv6, which is fine because hostnames reaching it are already stripped of ports. A short comment saying so would help.
  • (nit) The PR body lists known gaps: security/http-to-https redirect hops are not gated, and runRulesOnStorage does not take ownSiteOnly. Please track them as follow-up issues so they are not lost.

Test coverage looks thorough: the matcher unit tests, the crawler and engine tests using a second server and Host headers, and the rules tests. Docs, completions and the CHANGELOG are updated.

nc9 added 2 commits October 27, 2026 13:20
… site #819

A shared ownSiteHostMatcher (the host, its www or apex twin, project domains and their subdomains) now backs allowHost on the crawl's egress policy (page redirect hops, the seed redirect probe, discovery probes, the AI agent access probe), the sitemap walk (a sitemap named on another host is skipped and recorded, not requested), the asset checks and the link probe, and the soft-404 and cloaking probes; the CLI reachability probe stops at a redirect off the site. Assets on the www or apex twin or a project domain are read as the site's own in an offline audit. Docs, help text and CHANGELOG say what ships; tests prove each case by Host header against a second server, with a control where it is requested.

Signed-off-by: Nik Cubrilovic <[email protected]>
…eads as skipped; manifests use the shared own-site matcher; project domains with a port, wildcard or Unicode name match #819

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/819-offline-own-site branch from 30aab45 to c3a1237 Compare October 27, 2026 02:20
@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Review of #1171 (--offline holds every request to the audited site). I read the diff and the source. I did not run the tests.

The design is sound. One ownSiteHostMatcher feeds EgressPolicy.allowHost everywhere. The tests use a Host header, a second server and a control case. The PR body lists its own known gaps honestly. No blocking problems found.

  • (medium) packages/utils/src/own-site.ts The twin and subdomain rules are broad. With https://www.example.com as the site, the apex example.com and every *.example.com count as the site. That includes hosts the owner may not control, such as a status. or shop. subdomain on a third-party platform. It is documented, but this is a data-egress boundary. Please make sure docs/cli/audit.mdx says in plain words that subdomains are treated as own-site. Also consider whether a public-suffix host such as foo.github.io should be allowed to claim its github.io twin.
  • (low) apps/cli/src/utils/reachability.ts An off-site redirect is reported as reachable: true, statusCode: 302. This is a made-up status, and the real one is lost. Anything that later reads statusCode from the probe will show 302 even for a 301 or 307. Consider carrying the real status, or a flag such as offSiteRedirect.
  • (low) reachability.ts, sitemaps.ts Both compare error.message === EGRESS_OFF_SITE_REFUSAL to tell the refusal from an address refusal. A typed reason field on EgressRefusedError would be sturdier than string equality. Any future rewording of the message would silently turn "reachable" back into "unreachable".
  • (low) packages/crawler/src/sitemaps.ts In discoverSitemaps, the off-site skip fires whenever options.egress.allowHost is set, not only when the audit is offline. Today only ownSiteOnly sets it for that call (the only caller is crawler.ts:2919). A later caller that sets allowHost for another reason would get this behaviour by accident. An explicit flag would remove that risk.
  • (low) packages/audit-engine/src/adapter.ts The own-host check is built in several places: fetchResourceAssets, streaming-pre-rules, fetchAssetsFromOccurrences and probeEgress. Each one repeats the ownSiteOnly === true ? ownSiteHostMatcher(...) : undefined logic. A small helper would stop them drifting apart. The resident runRulesOnStorage path is already called out as a gap in the PR body. A follow-up issue for that, and for security/http-to-https having no allowHost, would help.
  • (nit) streaming-pre-rules.ts The new import leaves a stray blank line and is out of order with the other imports. Worth checking against the formatter.
  • (nit) sitemap-exists.ts The new comment runs past its line and splits awkwardly ("...(squirrel audit --offline: hold the crawl's own redirects and off-site sitemaps to the audited site #819), so with nothing found..."). Please reflow it.

Test coverage is good. The one gap I saw is IPv6 literal sites ([::1]) in own-site-819.test.ts. normalizeHost strips the brackets, so a case there would pin that behaviour down.

@nc9
nc9 merged commit c5c1e20 into main Oct 27, 2026
15 checks passed
@nc9
nc9 deleted the fix/819-offline-own-site branch October 27, 2026 02:37
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.

squirrel audit --offline: hold the crawl's own redirects and off-site sitemaps to the audited site

1 participant