Skip to content

fix(crawler): a refused seed probe must not collapse the crawl to one page - #248

Merged
nc9 merged 1 commit into
mainfrom
fix/seed-base-collapse-1899
Sep 7, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/seed-base-collapse-1899

Conversation

@nc9

@nc9 nc9 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The bug

A crawl whose seed is a bare apex that redirects to www sometimes audits one page and reports that as the whole site.

The crawl's base origin is pinned before anything else is fetched, from a single probe of the seed in detectRedirects. That probe went out under the runtime's default user agent, the only request in the whole crawl that did, and treated any readable response as proof of where the seed settles. An origin behind a WAF refuses that agent with a 403 carrying no Location, which the loop cannot tell apart from an apex that genuinely serves the site. So the base stayed on the apex, isInScope rejected every www. link off the homepage as cross_domain, the frontier emptied, and the crawl ended after the seed.

It flips run to run because the refusal does. Verified against a live origin: with an empty user agent the apex answers 403 with no redirect, and with a normal one it answers 301 to www.

The fix

Scope. A base pinned to a bare apex keeps that apex's www host in scope. The page fetch has the crawl's agent and its retry stack and gets through where the bare probe did not, so the crawl recovers from the seed page's own links even when the probe is refused for reasons the crawler cannot fix. The base must be a registrable domain, read straight off tldts rather than through registrableDomain(), whose fallback would let a public suffix, an IP literal or localhost qualify as its own apex. One direction only: a www base does not adopt the apex, which on these sites only redirects back.

Identity. The probe now sends config.userAgent, the way fetchRobots and every other root probe already do, when there is one to send. config.headers deliberately stay out of it: redirect: "follow" would hand them to whatever origin the chain lands on, and a custom header may be a credential (#1395).

Diagnosis. A 4xx/5xx hop logs why. The settled value is the same either way, since there is no second URL to fall back to, so this does not change the decision, it names it.

Notes for review

  • Link extraction already uses the page's final URL, so on the failing site the www links were classified internal and then dropped at the scope check. That is the line this changes.
  • robots.txt is fetched from the base through safeRedirectFetch, which follows 3xx, so an apex robots.txt that redirects to www yields www's rules. The newly admitted pages are governed by the file the origin actually serves.
  • maxPages is a plain count, so the apex and www halves share one budget. Per-host delay and concurrency stay keyed on host.

Tests

packages/crawler/tests/seed-base-collapse.test.ts drives the real start() with the two vantages disagreeing the way production did: globalThis.fetch refuses the apex probe while the page fetcher lands on www. It asserts on stored pages rather than fetch attempts, since a crawl that requests a URL and discards it is the same one-page audit from the report's point of view.

The suite fails 5 of 11 against the pre-fix source and passes against this one. Successful seed adoption stays covered by seed-redirect-pinning.test.ts against real servers: a constructed Response always reports an empty response.url, so a stub cannot model a followed redirect.

Ran locally, all green: the new suite plus seed-redirect-pinning, frontier-trailing-slash, frontier-url-length-cap, trailing-slash-canonical-crawl, carried-seed-crawl, redirect-header-security, full-crawl-harness, preamble-budget, root-failure-classification, injectable-cache-store, sitemap-gate, slow-origin-crawl, zero-success-breaker, crawler-stop-hard-cap, deterministic-ordering, and the CLI's graph/crawler/frontier. tsgo --noEmit clean, oxfmt and oxlint clean.

Refs squirrelscan/repo#1899

… page

The crawl's base origin is pinned from one unauthenticated probe of the seed,
before anything else is fetched. That probe went out under the runtime's
default user agent - the only request in the whole crawl that did - and read
any readable response as proof of where the seed settles. An origin behind a
WAF refuses that agent with a 403 carrying no Location, so an apex that does
redirect to www was recorded as not redirecting. The base stayed on the apex,
isInScope rejected every www link as cross_domain, the frontier emptied, and a
150-page audit fetched one page and charged for the rest with nothing in the
run saying why. It flips run to run because the refusal does.

Three changes, in order of how much they matter:

isInScope: a base pinned to a bare apex keeps that apex's www host in scope, so
the crawl recovers from the seed page's own links even when the probe is
refused for reasons the crawler cannot fix. The page fetch has the crawl's
agent and its retry stack, and gets through where the bare probe did not. The
base must BE its registrable domain, not merely lack a www prefix, or
shop.example.com would be handed the unrelated www.shop.example.com. One
direction only: a www base does not adopt the apex, which on these sites only
redirects back, so adopting it would re-crawl every page through a redirect.

The probe now identifies itself with config.userAgent, the way fetchRobots and
every other root probe already do, when there is one to send. config.headers
stay out of it: redirect: "follow" would hand them to whatever origin the chain
lands on, and a custom header may be a credential (#1395).

A refused hop logs why. The settled value is the same either way - there is no
second URL to fall back to - so this does not change the decision, it names it:
a crawl that later collapses to the seed alone now has one line saying the
origin refused the probe. The scope rule is the recovery; this is the
diagnosis.

The test drives the real start() with the two vantages disagreeing, the way
production did: globalThis.fetch refuses the apex probe while the page fetcher
lands on www. It asserts on STORED pages rather than fetch attempts, since a
crawl that requests a URL and discards it is the same one-page audit from the
report's point of view. Successful seed adoption stays covered by
seed-redirect-pinning.test.ts, against real servers: a constructed Response
always reports an empty response.url, so a stub cannot model a followed
redirect.

squirrelscan/repo#1899

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 merged commit 964dfbf into main Sep 7, 2026
13 checks passed
@nc9
nc9 deleted the fix/seed-base-collapse-1899 branch September 7, 2026 18:28
nc9 added a commit that referenced this pull request Sep 7, 2026
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 added a commit that referenced this pull request Sep 7, 2026
…249)

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]>
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