Repository navigation
fix(crawler): a refused seed probe must not collapse the crawl to one page - #248
Merged
Merged
Conversation
… 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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
A crawl whose seed is a bare apex that redirects to
wwwsometimes 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 a403carrying noLocation, which the loop cannot tell apart from an apex that genuinely serves the site. So the base stayed on the apex,isInScoperejected everywww.link off the homepage ascross_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
403with no redirect, and with a normal one it answers301towww.The fix
Scope. A base pinned to a bare apex keeps that apex's
wwwhost 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 throughregistrableDomain(), whose fallback would let a public suffix, an IP literal orlocalhostqualify as its own apex. One direction only: awwwbase does not adopt the apex, which on these sites only redirects back.Identity. The probe now sends
config.userAgent, the wayfetchRobotsand every other root probe already do, when there is one to send.config.headersdeliberately 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/5xxhop 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
wwwlinks were classified internal and then dropped at the scope check. That is the line this changes.robots.txtis fetched from the base throughsafeRedirectFetch, which follows3xx, so an apexrobots.txtthat redirects towwwyieldswww's rules. The newly admitted pages are governed by the file the origin actually serves.maxPagesis a plain count, so the apex andwwwhalves share one budget. Per-host delay and concurrency stay keyed on host.Tests
packages/crawler/tests/seed-base-collapse.test.tsdrives the realstart()with the two vantages disagreeing the way production did:globalThis.fetchrefuses the apex probe while the page fetcher lands onwww. 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.tsagainst real servers: a constructedResponsealways reports an emptyresponse.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'sgraph/crawler/frontier.tsgo --noEmitclean, oxfmt and oxlint clean.Refs squirrelscan/repo#1899