Skip to content

scrape: the private-address guard lives only in module-travel, and the robots.txt fetch is unbounded #2502

Closed

Description

@schlessera

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 clearToFetch calls policy.robots.forUrl(url) on every hop, and only when respectRobots is true (packages/scrape/src/politeness/policy.ts:14-15). With robots turned off, the address check silently disappears. The comment at route.ts:67-68 names this dependency, but scrape does not document it as a contract.
  • Check-then-connect. publicUrl resolves with lookup() and the subsequent fetch resolves 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 ScrapeClient gets 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, whatever respectRobots is set to. Move travel's blocklists and publicUrl into scrape for this.
  • Give RobotsCacheOptions a userAgent, a body-size limit and a redirect limit with a per-hop address check. ScrapeClient and createBrowserSession pass their user agent and address policy into the cache they build.
  • Move module-travel/src/route.ts onto the option and delete RouteRobots, publicUrl and the blocklists there.
  • Record whether Bun's fetch can 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 in packages/scrape/README.md.

Out of scope

Acceptance criteria

  • With addressPolicy: "public-only", a scrape test with an injected resolver refuses 127.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 with respectRobots: 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-travel returns 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 lint

Contract 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

  1. added
    type: fix
    area: modules
    area: scrape
    priority: p1
    agent-ready
    contract
    security
    on Oct 21, 2026
  2. self-assigned this
    on Nov 2, 2026
  3. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claiming this issue (claim token c2502-2c7cb4e2). Intended branch: fix/2502-private-address-guard-robots from origin/main at 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.

  4. added this to the 0.45.0 milestone on Nov 2, 2026
  5. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    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 of respectRobots. On the native path it pins the checked address (Host and tls.serverName keep the name). The proxy path's remaining window is documented in packages/scrape/README.md.
    • The robots.txt fetch sends the client's User-Agent, follows at most maxRedirects (5) and refuses a body over maxBytes (1 MiB).
    • module-travel uses the option. RouteRobots, publicUrl and the blocklists are gone.

    The failing-first and mutation receipts are in the PR body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: modulesarea: scrapecontractpriority: p1securitytype: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions