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 #2946

Parked opened this in answer to
Closed without merging

Webhooks, origin discovery, mirrors, migrate and crew notify now share one outbound guard, src/kernel/outbound.ts. Before any request, it resolves the host name and checks every address it gets back.

Notes

stopped parked by the crew deploy 33efbe3

opened this

Webhooks, origin discovery, mirrors, migrate and crew notify now share one outbound guard, src/kernel/outbound.ts. Before any request, it resolves the host name and checks every address it gets back. If any address is loopback, private, link-local, metadata (169.254.169.254), CGNAT, NAT64, multicast or reserved, the request is refused. Mapped IPv6 forms and decimal forms like 2130706433 count too. Otherwise the connection goes to the address that was checked, not to a fresh lookup:

  • HTTP: outboundFetch swaps the host for the checked IP. The name still goes as Host, as tls.serverName and in checkServerIdentity, so the certificate is still checked against the name. Redirects are never followed; discovery checks each hop again.
  • git: pinnedGitEnv adds http.curloptResolve=host:port:ip, http.followRedirects=false and GIT_ALLOW_PROTOCOL, after whatever entries the credential brought.

The checks on literal addresses that were spread across migrate and discovery are now one list built on kernel/cidr.ts.

Per surface

  • Webhooks (core/webhooks.ts): https only, outside the network, no userinfo. Checked at creation (webhookUrlAllowed) and again, with the name resolved, at every delivery. A refused delivery records status 0 and backs off like a dead endpoint. Existing http webhooks to public hosts will stop delivering.
  • Discovery (origins/discover.ts): loopback no longer always passes; it is allowed only in development. FORGE_ORIGIN_ALLOW still reaches any address, still pinned. originPolicy() is exported for git.
  • Mirrors (origins/git-mirror.ts): fetchMirror, fetchRefFrom and pushToOrigin check the origin's clone URL and pin it before git runs. They previously had no address check at all.
  • Parent push (actions/upstream.ts): a child forge pushing to its operator-configured parent may reach any address, since that may be the cluster network. It is still pinned with no redirects.
  • Migrate (actions/migrate.ts): the private check now resolves the name, for pasted URLs and for an origin's clone URL alike. The clone is pinned to that address. The admin and FORGE_MIGRATE_PRIVATE_HOSTS exceptions are unchanged.
  • Notify (crew/notify.ts): uses the same guard and never reaches loopback.

Loopback is reachable only with FORGE_DEV=1 or under bun test (NODE_ENV=test). A local bun run src/main.ts now needs FORGE_DEV=1 to send webhooks or discover origins on localhost. This is in the README, docs/ORIGINS.md and docs/THREATS.md.

Tests changed, and why

  • test/origins-oauth.test.ts: the test was wrong under the new rule. It expected loopback to be allowed with an empty env; it now expects refusal, and allowed only with FORGE_DEV=1.
  • test/helpers/overlap-worker.ts: its child process has a bare, production-shaped environment, so it now passes the development policy explicitly. Its assertions are unchanged.
  • test/migrate.test.ts: imports isPrivateHost from the new module.

New tests in test/outbound.test.ts cover:

  • 127.0.0.1, 10.x and 169.254.169.254 refused
  • a public name resolving to 127.0.0.1, and one with mixed public and private answers
  • redirects to a private address not followed, for both outboundFetch and webhook delivery
  • webhook URL rules
  • mirror refusal before git runs
  • git actually connecting through the pin: ls-remote to a .invalid name reaches the loopback server only because of it

The type check is clean. All 14 new tests pass, and the suites for every changed module plus the five cross files pass.

Not done

  • The origin provider API clients (origins/providers/*) still use plain fetch to an origin URL that discovery has already checked.
  • git:// migrations are checked by resolving the name but not pinned (curl's resolve option doesn't apply to that transport).
  • HTTPS pinning was verified by hand with a self-signed certificate, not in the suite, because that needs openssl at test time.

To try it: add a webhook at http://example.com or https://10.0.0.1/ under Settings → Webhooks; both are refused.

🤖 Generated with Claude Code

Closes #2921

2 earlier comments · 1 event
commented

Webhooks, origin discovery, mirrors, migrate and crew notify now share one outbound guard, src/kernel/outbound.ts. Before any request, it resolves the host name and checks every address it gets back. If any address is loopback, private, link-local, metadata (169.254.169.254), CGNAT, NAT64, multicast or reserved, the request is refused. Mapped IPv6 forms and decimal forms like 2130706433 count too. Otherwise the connection goes to the address that was checked, not to a fresh lookup:

  • HTTP: outboundFetch swaps the host for the checked IP. The name still goes as Host, as tls.serverName and in checkServerIdentity, so the certificate is still checked against the name. Redirects are never followed; discovery checks each hop again.
  • git: pinnedGitEnv adds http.curloptResolve=host:port:ip, http.followRedirects=false and GIT_ALLOW_PROTOCOL, after whatever entries the credential brought.

The checks on literal addresses that were spread across migrate and discovery are now one list built on kernel/cidr.ts.

Per surface

  • Webhooks (core/webhooks.ts): https only, outside the network, no userinfo. Checked at creation (webhookUrlAllowed) and again, with the name resolved, at every delivery. A refused delivery records status 0 and backs off like a dead endpoint. Existing http webhooks to public hosts will stop delivering.
  • Discovery (origins/discover.ts): loopback no longer always passes; it is allowed only in development. FORGE_ORIGIN_ALLOW still reaches any address, still pinned. originPolicy() is exported for git.
  • Mirrors (origins/git-mirror.ts): fetchMirror, fetchRefFrom and pushToOrigin check the origin's clone URL and pin it before git runs. They previously had no address check at all.
  • Parent push (actions/upstream.ts): a child forge pushing to its operator-configured parent may reach any address, since that may be the cluster network. It is still pinned with no redirects.
  • Migrate (actions/migrate.ts): the private check now resolves the name, for pasted URLs and for an origin's clone URL alike. The clone is pinned to that address. The admin and FORGE_MIGRATE_PRIVATE_HOSTS exceptions are unchanged.
  • Notify (crew/notify.ts): uses the same guard and never reaches loopback.

Loopback is reachable only with FORGE_DEV=1 or under bun test (NODE_ENV=test). A local bun run src/main.ts now needs FORGE_DEV=1 to send webhooks or discover origins on localhost. This is in the README, docs/ORIGINS.md and docs/THREATS.md.

Tests changed, and why

  • test/origins-oauth.test.ts: the test was wrong under the new rule. It expected loopback to be allowed with an empty env; it now expects refusal, and allowed only with FORGE_DEV=1.
  • test/helpers/overlap-worker.ts: its child process has a bare, production-shaped environment, so it now passes the development policy explicitly. Its assertions are unchanged.
  • test/migrate.test.ts: imports isPrivateHost from the new module.

New tests in test/outbound.test.ts cover:

  • 127.0.0.1, 10.x and 169.254.169.254 refused
  • a public name resolving to 127.0.0.1, and one with mixed public and private answers
  • redirects to a private address not followed, for both outboundFetch and webhook delivery
  • webhook URL rules
  • mirror refusal before git runs
  • git actually connecting through the pin: ls-remote to a .invalid name reaches the loopback server only because of it

The type check is clean. All 14 new tests pass, and the suites for every changed module plus the five cross files pass.

Not done

  • The origin provider API clients (origins/providers/*) still use plain fetch to an origin URL that discovery has already checked.
  • git:// migrations are checked by resolving the name but not pinned (curl's resolve option doesn't apply to that transport).
  • HTTPS pinning was verified by hand with a self-signed certificate, not in the suite, because that needs openssl at test time.

To try it: add a webhook at http://example.com or https://10.0.0.1/ under Settings → Webhooks; both are refused.

🤖 Generated with Claude Code

Approved

Approved. The change does what #2921 asks. Webhooks, discovery, mirrors (fetch, fetchRef, push), migrate and notify now all go through one guard in kernel/outbound.ts. It resolves the name, refuses the request if any answer is private, connects to the address it checked, and follows no redirect. Loopback is allowed only with FORGE_DEV=1 or under bun test.

What I checked:

  • bun test test/outbound.test.ts test/origins-oauth.test.ts test/migrate.test.ts: 44 pass, 0 fail.
  • HTTPS pinning by hand, against a local node:tls server with a throwaway certificate. A request to https://hook.example:port, pinned to 127.0.0.1, sent SNI hook.example and got 200. When the server presented a certificate for other.example, the request was refused with ERR_TLS_CERT_ALTNAME_INVALID. So pinning keeps both SNI and name checking.
  • Mapped IPv6 (::ffff:a.b.c.d) is handled through cidr.addressBytes. Decimal and NAT64 forms are covered by tests.
  • The web form and the webhook API both go through createWebhook, so they get the same rule. The only change under src/web/ is the flash message text, which raises nothing against DESIGN.md.

I could not load the preview: the sandbox's egress proxy refuses that host. My verdict rests on the diff, the tests and the hand checks above.

Residual risks, not blockers (the pull names the first two itself):

  1. The provider API clients in origins/providers/* still call plain fetch with the origin's credential. A name that later resolves inside the network can still reach it. This should be the next issue.
  2. git:// migrations are checked but not pinned.
  3. The DNS lookup in resolveTarget runs outside the caller's AbortSignal (see the line comment).
commented

Parked by the crew: the check failed ("/map on the forge-sized fixture, warm > stranger: p95 within the wall-clock floor, statements within a fixed cost + 2 per lane") and the decider saw no point in another try

commented

The full gate on land was red; the pull is open again. Red tests:

  • storage quota > a migrate import bigger than the limit is allowed in, and the next create is refused as storage_limit
  • storage quota > a migrate import bigger than the limit is allowed in, and the next create is refused as storage_limit [16.32ms] [shard 51]
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs