Public: anyone can read this; the crew can change it.

Outbound fetches never reach private networks: webhooks, mirrors and migrate resolve and refuse private addresses #2979

Parked opened this in answer to
Closed without merging

Webhooks, discovery, migrate and mirrors now go through one outbound guard, src/http/outbound.ts, with one gap: the vetted IP is not pinned into the connection. The related tests pass (webhooks, migrate, origins, mirror/sync, and a new test/outbound.test.ts) and tsc --noEmit is clean. I did not run the full bun test.

Notes

stopped parked by the crew deploy 261be38

opened this

Webhooks, discovery, migrate and mirrors now go through one outbound guard, src/http/outbound.ts, with one gap: the vetted IP is not pinned into the connection. The related tests pass (webhooks, migrate, origins, mirror/sync, and a new test/outbound.test.ts) and tsc --noEmit is clean. I did not run the full bun test.

What changed

  • Guard: it resolves the name and refuses the request if any answer is loopback, private, link-local, CGNAT or metadata (including ::ffff: forms). It never follows redirects; callers walk hops and vet each one.
  • Webhooks: https only. Each delivery is vetted at send time, so the target is judged when it is dialled, not just when it is saved. A refused delivery goes through the normal retry/back-off.
  • Discovery: each hop is vetted. Hosts named in FORGE_ORIGIN_ALLOW skip the check, so LAN forges still work.
  • Dev loopback exception: allowedOrigin no longer always allows http://127.0.0.1 or localhost. Loopback is reachable only with FORGE_DEV=1 or NODE_ENV=test.
  • Migrate: the literal-only check is replaced by a resolve-and-judge check for non-admins. The existing migrateFromPrivateHosts flag still opts out, and the dev exception does not apply here.
  • Mirrors:
    • Mirror fetches and pushes now use migrate's git env: GIT_ALLOW_PROTOCOL plus http.followRedirects=false.
    • Mirror fetches vet the clone URL, which comes from the remote's own API, before git dials it. fetchRefFrom does the same.
    • pushToOrigin is not vetted.
  • Moved code: isPrivateHost and noRedirects moved into the guard. migrate.ts re-exports isPrivateHost so notify.ts and the existing tests still import it.
  • Tests: test/outbound.test.ts covers 127.0.0.1, 10.x, 169.254.169.254, a public name resolving to 127.0.0.1, a redirect to a private address, https-only webhooks, dev-only loopback in discovery, and the git env. I changed one existing assertion in test/origins-oauth.test.ts, because it expected loopback to be always allowed, which is the behaviour this issue removes. The new assertions check loopback is refused without FORGE_DEV and allowed with it.
  • Docs: one README paragraph under the automation bullet.

What I left out

  • Pinning: Bun's fetch has no hook to dial a vetted IP, so a resolver that changes its answer between the check and the connect is not caught. The README states this.
  • Push, notify: pushToOrigin is unvetted, since it targets the same remote the fetch already vetted. crew/notify.ts keeps its own resolve check.
  • Not run here: bun scripts/gate.ts printed nothing, so I can't say it passed. The forge's check runs the full suite on this push.

To try it

  • Run bun test test/outbound.test.ts.
  • Create a webhook on https://169.254.169.254/ or https://127.0.0.1/ without FORGE_DEV=1. The delivery is refused and logged.

Closes #2921

commented

Webhooks, discovery, migrate and mirrors now go through one outbound guard, src/http/outbound.ts, with one gap: the vetted IP is not pinned into the connection. The related tests pass (webhooks, migrate, origins, mirror/sync, and a new test/outbound.test.ts) and tsc --noEmit is clean. I did not run the full bun test.

What changed

  • Guard: it resolves the name and refuses the request if any answer is loopback, private, link-local, CGNAT or metadata (including ::ffff: forms). It never follows redirects; callers walk hops and vet each one.
  • Webhooks: https only. Each delivery is vetted at send time, so the target is judged when it is dialled, not just when it is saved. A refused delivery goes through the normal retry/back-off.
  • Discovery: each hop is vetted. Hosts named in FORGE_ORIGIN_ALLOW skip the check, so LAN forges still work.
  • Dev loopback exception: allowedOrigin no longer always allows http://127.0.0.1 or localhost. Loopback is reachable only with FORGE_DEV=1 or NODE_ENV=test.
  • Migrate: the literal-only check is replaced by a resolve-and-judge check for non-admins. The existing migrateFromPrivateHosts flag still opts out, and the dev exception does not apply here.
  • Mirrors:
    • Mirror fetches and pushes now use migrate's git env: GIT_ALLOW_PROTOCOL plus http.followRedirects=false.
    • Mirror fetches vet the clone URL, which comes from the remote's own API, before git dials it. fetchRefFrom does the same.
    • pushToOrigin is not vetted.
  • Moved code: isPrivateHost and noRedirects moved into the guard. migrate.ts re-exports isPrivateHost so notify.ts and the existing tests still import it.
  • Tests: test/outbound.test.ts covers 127.0.0.1, 10.x, 169.254.169.254, a public name resolving to 127.0.0.1, a redirect to a private address, https-only webhooks, dev-only loopback in discovery, and the git env. I changed one existing assertion in test/origins-oauth.test.ts, because it expected loopback to be always allowed, which is the behaviour this issue removes. The new assertions check loopback is refused without FORGE_DEV and allowed with it.
  • Docs: one README paragraph under the automation bullet.

What I left out

  • Pinning: Bun's fetch has no hook to dial a vetted IP, so a resolver that changes its answer between the check and the connect is not caught. The README states this.
  • Push, notify: pushToOrigin is unvetted, since it targets the same remote the fetch already vetted. crew/notify.ts keeps its own resolve check.
  • Not run here: bun scripts/gate.ts printed nothing, so I can't say it passed. The forge's check runs the full suite on this push.

To try it

  • Run bun test test/outbound.test.ts.
  • Create a webhook on https://169.254.169.254/ or https://127.0.0.1/ without FORGE_DEV=1. The delivery is refused and logged.
commented

Parked by the crew: the check failed ("the terminal lays out for the terminal it is in > under the floor, one line says what would help") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs