Skip to content

feat(crawler): say when the crawl's base is the wrong host of a pair - #249

Merged
nc9 merged 1 commit into
mainfrom
fix/seed-base-mismatch-warning-1915
Sep 7, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/seed-base-mismatch-warning-1915

Conversation

@nc9

@nc9 nc9 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The second detector for squirrelscan/repo#1899, requested after #248 merged.

#248 stopped a mis-pinned base from collapsing the crawl to one page. That fixed the damage but not the silence: the audit still describes a host the site redirects away from, and now it does so while looking entirely healthy. That silence is how this went unnoticed for weeks, and how a paying customer was charged in full for a one-page audit of a ten-page site.

What it detects

The base is pinned from one probe of the seed before anything is fetched. The seed page's own fetch is the first thing that can contradict it, and three things about it are evidence, in descending strength:

  1. Where the fetch landed. Outside the HTML branch and needing no body, so a seed serving a PDF still proves which host the site is on.
  2. The canonical the page declares. Resolved against the page since it may be relative, and only on a 2xx: an error page's canonical describes the error template, not the site.
  3. The page's links, when not one of them points back at the base. Read off parsed.links rather than the crawlable set, because that set is already filtered to the page's own hostname and so is empty on exactly the origin this describes: an apex serving the site while every link points at www. One link home is enough to stay silent.

A different site is not this. That is the #1418 case, refused deliberately by resolveSeedRedirect and logged where it happens; repeating it here would turn a security decision into a bug report.

It reports once per crawl and does not move the base. It cannot: the root probes have already run against it, and re-basing mid-crawl would file one origin's content under another's name. So it fires on crawls that then succeed, deliberately. The message states what was observed and offers the missed redirect as the likely cause rather than asserting it, since an apex can serve content and canonicalise elsewhere without ever redirecting.

Why an event and not just a log line

logger.warn reaches a terminal or a container's stdout, neither of which is where a hosted run is investigated weeks later. This rides the event stream the run already records, on a new warning member of CrawlerEvent.

Two things a reviewer should know:

  • CrawlerEvent is duplicated, in packages/core-contracts/src/index.ts and in the crawler's own src/core/types.ts. Consumers outside the crawler package read the core-contracts copy, so an event added to one and not the other type-checks locally and is invisible to every consumer. Both move here, and the shared CrawlWarningCode keeps the machine key from drifting.
  • No consumer handles the type yet, so it is currently inert: the CLI switches handle only page:*, progress, completed, started, resumed and url:*, and the hosted container forwards only progress, page:fetched and page:failed. A small handler on the private side is what lands it in agent_run_events, and is tracked separately.

Tests

packages/crawler/tests/seed-base-collapse.test.ts grows to 21 cases, covering each detector, the once-per-crawl guard, and the cases that must stay silent: a base that agrees with its seed page, one link back to the base, an in-page anchor or mailto: that must not veto the link evidence, and unrelated domains that must neither trigger it nor be named in the message.

The collector now records every event type and joins its fiber with a failing timeout instead of ignoring it, so a silent-warning assertion can no longer pass against a dead subscription. The silent case asserts it saw page:fetched and completed.

Two codex rounds on the diff; every finding addressed or answered with evidence. The fragment-veto concern turned out not to be reachable, because shouldSkipUrl drops #-only hrefs and non-crawlable schemes before parsed.links is built, and there is now a test pinning that.

Green locally: the new suite, plus seed-redirect-pinning, carried-seed-crawl, full-crawl-harness, trailing-slash-canonical-crawl, incremental-freshness, sitemap-gate, rate-limit-crawl, slow-origin-crawl, injectable-cache-store, deterministic-ordering. tsgo --noEmit clean for the crawler and the CLI, oxfmt and oxlint clean.

Refs squirrelscan/repo#1899

The second detector for squirrelscan/repo#1899. #248 stopped a mis-pinned base
from collapsing the crawl to one page, which fixed the damage but not the
silence: the audit still describes a host the site redirects away from, and now
it does so while looking entirely healthy. That is how this went unnoticed for
weeks and how a paying customer was charged for a one-page audit of a ten-page
site.

The base is pinned from one probe of the seed before anything is fetched. The
seed page's own fetch is the first thing that can contradict it, and three
things about it are evidence, in descending strength:

- where the fetch LANDED. Outside the HTML branch and needing no body, so a
  seed serving a PDF still proves which host the site is on.
- the CANONICAL the page declares, resolved against the page since it may be
  relative, and only on a 2xx: an error page's canonical describes the error
  template.
- the page's LINKS, when not one of them points back at the base. Read off
  parsed.links rather than the crawlable set, because that set is already
  filtered to the page's own hostname and so is empty on exactly the origin
  this describes. One link home is enough to stay silent; a single stray
  same-site link proves nothing.

A different SITE is not this. That is the #1418 case, refused deliberately by
resolveSeedRedirect and logged where it happens; repeating it here would turn a
security decision into a bug report.

It reports and does not move the base. It cannot: the root probes have already
run against it, and re-basing mid-crawl would file one origin's content under
another's name. So it fires on crawls that then succeed, deliberately. The
message says what was observed and offers the missed redirect as the likely
cause rather than asserting it, since an apex can serve content and canonicalise
elsewhere without ever redirecting.

Carried on a new `warning` member of CrawlerEvent rather than logger.warn alone:
a log line reaches a terminal or a container's stdout, neither of which is where
a hosted run is investigated weeks later. Note that CrawlerEvent is DUPLICATED
between core-contracts and the crawler's own types.ts; both move here, and the
shared CrawlWarningCode keeps the machine key from drifting. No consumer handles
the type yet, so it is inert until one does.

The test collector now records every event and joins its fiber instead of
ignoring the timeout, so a silent-warning assertion cannot pass against a dead
subscription.

squirrelscan/repo#1899

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/seed-base-mismatch-warning-1915 branch from 201f828 to 34aedac Compare September 7, 2026 19:08
@nc9
nc9 merged commit c031481 into main Sep 7, 2026
13 checks passed
@nc9
nc9 deleted the fix/seed-base-mismatch-warning-1915 branch September 7, 2026 19:14
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