Repository navigation
Description
Context
The only private-address (SSRF) guard on the outbound HTTP path belongs to one module. packages/module-travel/src/route.ts:21-45 defines forbiddenV4, publicV6, documentationV6, httpUrl and publicUrl. Its only path into a fetch is the RouteRobots subclass (:67-84), which overrides RobotsCache.forUrl to run publicUrl first and is passed in at :137 (new ScrapeClient({ robots: new RouteRobots() })).
git grep -n "BlockList\|169.254.0.0" -- 'packages/*/src/**'
# only packages/module-travel/src/route.ts (plus ui-server's unrelated loopback check)That wiring rests on three things scrape does not promise:
- The guard depends on robots being on. It works only because
clearToFetchcallspolicy.robots.forUrl(url)on every hop, and only whenrespectRobotsis true (packages/scrape/src/politeness/policy.ts:14-15). With robots turned off, the address check silently disappears. The comment atroute.ts:67-68names this dependency, but scrape does not document it as a contract. - Check-then-connect.
publicUrlresolves withlookup()and the subsequentfetchresolves again, so a host whose DNS answer changes between the two (DNS rebinding) passes the check and connects to a private address. - No other caller is protected. A module that fetches a user-supplied URL through
ScrapeClientgets no address policy.
The default robots.txt fetch is unbounded and unidentified. defaultFetcher (packages/scrape/src/politeness/robots.ts:58-67) sends no User-Agent, follows redirects with redirect: "follow" and no hop limit or per-hop check, and reads the whole body with res.text(). ScrapeClient constructs its RobotsCache without passing its user agent (packages/scrape/src/fetch/http.ts:204, and packages/scrape/src/browser/session.ts:149). So the first request every site sees from brain-scrape uses Bun's default identity. That contradicts SCRAPE_USER_AGENT ("sent with every request", packages/scrape/src/config/env.ts:51-55). Travel's fetcher had to re-implement all three bounds (route.ts:70-80).
This is distinct from #1818, which is about a per-request User-Agent header diverging from the robots-matching identity. That issue does not cover the robots.txt fetch itself.
Scope
- Add an explicit address policy to
@schlessera/brain-scrape, e.g.ScrapeClientOptions.addressPolicy: "any" | "public-only"(default"any")."public-only"is enforced on the initial request, every redirect hop and the robots.txt fetch, whateverrespectRobotsis set to. Move travel's blocklists andpublicUrlinto scrape for this. - Give
RobotsCacheOptionsauserAgent, a body-size limit and a redirect limit with a per-hop address check.ScrapeClientandcreateBrowserSessionpass their user agent and address policy into the cache they build. - Move
module-travel/src/route.tsonto the option and deleteRouteRobots,publicUrland the blocklists there. - Record whether Bun's
fetchcan connect to a pre-resolved address while keeping TLS server-name verification. If it can,"public-only"pins the checked address. If it cannot, document the remaining rebinding window inpackages/scrape/README.md.
Out of scope
- The per-request
User-Agentheader precedence (scrape: request User-Agent headers diverge from robots identity #1818). - Response-body deadlines on ordinary requests (scrape: response-body reads outlive the HTTP timeout #1817).
- Turning
"public-only"on for job boards or other callers that do not take user-supplied URLs. - Browser-session navigation address policy. The headless path has its own posture (
packages/scrape/src/browser/session.ts:1-11).
Acceptance criteria
- With
addressPolicy: "public-only", a scrape test with an injected resolver refuses127.0.0.1,10.0.0.1,169.254.169.254,[::1],[fc00::1]and a public host whose redirect points at a private address. No request reaches the loopback fixture, and the same holds withrespectRobots: false. The tests fail before the change. - A robots.txt test against a loopback fixture shows the fetch carries the client's
User-Agent, stops at the configured redirect limit and refuses a body over the configured size. -
git grep -n "class RouteRobots\|forbiddenV4" -- packages/module-travelreturns nothing, and travel's existing route-import tests still pass. - The PR states the outcome of the address-pinning check, and the scrape README documents either the pinning or the remaining window.
- Mutation receipt: make
"public-only"skip redirect hops and watch the named redirect test fail.
Verification
bun run test packages/scrape packages/module-travel
bun run api-report
bun run typecheck
bun run lintContract impact
This adds options to ScrapeClientOptions and RobotsCacheOptions, both public in @schlessera/brain-scrape and described in docs/integration-contract/package-api.md. That is an additive CONTRACT: change: update api-report/scrape.txt and that doc, and add a changeset. The robots.txt fetch starts sending a User-Agent and enforcing limits, which is a behaviour change for the changeset.
Found by a repository review on 2026-10-22.
Activity
schlessera commentedon Nov 2, 2026
Claiming this issue (claim token
c2502-2c7cb4e2). Intended branch:fix/2502-private-address-guard-robotsfromorigin/mainat b228b1f.Collision check on the cited files: no path collisions; closure-level overlap (scrape/module-travel/module-jobs workspaces) with open drafts #3059, #3277, #3278, #3279.
CONTRACT: feat(scrape): add a public-only address policy and bound th…
schlessera commentedon Nov 2, 2026
Delivered by #3283, squash-merged as abd5fd6 on main (parent b228b1f, tree 421589810, identical to the candidate checkout c48c4cd that passed confirmation run 41448018975). Milestone 0.45.0.
ScrapeClientOptions.addressPolicy: "public-only"is enforced on the initial request, every redirect hop and the robots.txt fetch, independently ofrespectRobots. On the native path it pins the checked address (Hostandtls.serverNamekeep the name). The proxy path's remaining window is documented inpackages/scrape/README.md.maxRedirects(5) and refuses a body overmaxBytes(1 MiB).RouteRobots,publicUrland the blocklists are gone.The failing-first and mutation receipts are in the PR body.