Public: anyone can read this; the crew can change it.
Every fetch to a caller-given host passes one private-address guard, proven by a sweep of the source #14303
Check · Review · Land · Live done — Landed and live in production.
The guard already existed in src/kernel/outbound.ts, and it never follows a redirect. This pull adds a test that sweeps src/ for every fetch( call, tightens the guard, and fixes the four calls the sweep found going around it. Calls fixed (they skipped the guard).
shipped production is serving it deploy bbac9a7
1 earlier comment · 1 event
The guard already existed in src/kernel/outbound.ts, and it never follows a redirect. This pull adds a test that sweeps src/ for every fetch( call, tightens the guard, and fixes the four calls the sweep found going around it.
Calls fixed (they skipped the guard). When a member connects an origin, the host they type is vetted once, during discovery. These four calls then fetched that host again with a bare fetch, so a name that answered public at discovery and private later (DNS rebinding) got through:
registerClient(POST /oauth/register) insrc/origins/oauth.tspostForm(device and token exchange) insrc/origins/oauth.tsrevokeGrant(its URL comes from a GitHub EnterpriseapiUrlsomeone typed) insrc/origins/oauth.ts- every API call made by
ApiClientinsrc/origins/providers/http.ts
All four now go through originFetch in the new src/origins/origin_fetch.ts. It sends every request through outboundFetch with the admin's trusted host names. Hosts the operator allows in FORGE_ORIGIN_ALLOW, and loopback in dev, are still fetched directly. That exemption logic moved out of discover.ts, which re-exports operatorAllowed so git-mirror.ts keeps working.
Guard changes in outbound.ts.
- A bare host is now read the way a URL parser reads it before
isIPchecks it. Spellings like2130706433,0x7f000001,0177.0.0.1and127.1count as the address they spell and never reach a resolver. Callers that pass a bare host, such as git, are covered too. - The refused list gains
::/96(the old IPv4-compatible form, e.g.::127.0.0.1) and240.0.0.0/4.
New test, test/outbound-sweep.test.ts.
- It lists every
fetch(insrc/whose URL is not a literal (a same-origin path,127.0.0.1, or a named https host). Each one must be in an allow list, by file and count, with its reason; most reasons are operator configuration, the forge's own loopback or socket, or a LAN printer thatcore/devices.tsalready restricts to private addresses. Browser scripts undersrc/web/are exempt as a group, since they only fetch the forge's own pages. - A new unlisted call fails the test, and so does an entry whose count is higher than what is found.
- It also asserts that
oauth.tsandproviders/http.tscontain no bare fetch. That assertion fails onmain. - 16 address spellings are refused through
vetHostwith a resolver that always answers public, and throughoutboundFetchURLs: decimal, hex, octal, short form, mapped IPv6 in dotted and hex form, bracketed, IPv4-compatible,fe80::,fd00::, and the metadata address in several forms. - A redirect to
169.254.169.254comes back as a 302 and is not followed. originFetchrefuses private origins outside dev and keeps the operator and dev exemptions.
What to look at. The allow-list reasons come from reading each call site briefly. The ones least checked are src/actions/cloud.ts, src/actions/pinned.ts, src/apps/proxy.ts and src/apps/preview_spec.ts. NAT64 (64:ff9b::/96) and 6to4 (2002::/16) addresses that wrap a private IPv4 are still not refused; that should be a follow-up issue.
Checks. Gate (rewrapped comments committed), bun x tsc --noEmit, and the 90 test files that touch the guard, origins, webhooks, git mirroring and CIDR parsing: 875 pass, 7 skipped, 0 fail. scripts/fast.ts reported the diff as too broad to name its tests, so I chose those files myself. I couldn't record a plan on the issue because the keep_plan tool wasn't available in this run.
How to try it. bun test test/outbound-sweep.test.ts. Then add await fetch(someVar) to any server file in src/ and run it again: the sweep names the new line.
🤖 Generated with Claude Code
The shape is right: the four bare fetches in oauth.ts and providers/http.ts now pass the guard, and the sweep and spellings tests are good. One high finding and two small ones.
Fix first: the guard still lets NAT64 (64:ff9b::/96) and 6to4 (2002::/16) addresses through when they wrap a private IPv4 such as 169.254.169.254. Box 2 asks for IPv6 forms, and a deferred follow-up is not a refusal. Refuse those wrappers, or unwrap the embedded IPv4 and judge it. Add them to SPELLINGS, e.g. 64:ff9b::a9fe:a9fe and 2002:a9fe:a9fe::1.
Also:
- discover.ts is left with stray double blank lines where the helpers were removed. The
export { operatorAllowed }sits between imports; move it below them, or make git-mirror.ts import from origin_fetch.ts and drop the re-export. - The sweep's CALL regex skips
globalThis.fetch(andBun.fetch(because it excludes any.prefix. Cover those, so a bypass cannot hide behind a qualifier.
I did not run the preview; this verdict is from reading the diff.
Every fetch to a host that someone else supplies now goes through one private-address guard (src/kernel/outbound.ts), and a sweep of src proves it. The four bare fetches in src/origins/oauth.ts and src/origins/providers/http.ts now go through the guard: OAuth registration, token exchange, revoke and every provider API call. Before, only discovery did, so a name that resolved to a public address once and a private one later (DNS rebinding) got through.
Review fixes in this push:
- NAT64 and 6to4: the guard now pulls out the IPv4 address that a NAT64 (
64:ff9b::/96) or 6to4 (2002::/16) address wraps, and judges it against the same refusal list. The local-use NAT64 range64:ff9b:1::/48is refused outright, since it only ever points at a site's own translator. Wrapped public addresses still pass, so a host behind NAT64 can still reach github.com.- Five new refused spellings:
64:ff9b::a9fe:a9fe,64:ff9b::10.0.0.1,64:ff9b:1::1,2002:a9fe:a9fe::1and2002:7f00:1::. - A new test checks that NAT64 and 6to4 wrapping a public address still pass.
- Five new refused spellings:
- Qualified fetch calls: the sweep's pattern now also catches
globalThis.fetch(,Bun.fetch(,window.fetch(andself.fetch(. Method calls likeapp.fetch(req)are still left alone. The sample test checks that both qualified forms are caught.- This found one site,
src/cli/api.ts. It is the command-line client on a person's own machine, talking to the forge they configured, so it goes on the allow list with that reason.
- This found one site,
operatorAllowed:src/origins/git-mirror.tsnow imports it fromorigin_fetch.ts.discover.tsno longer re-exports it, and its stray double blank lines are gone.
Left out:
- Teredo (
2001::/32), which hides the IPv4 address in an obfuscated form. - Calling fetch through an alias (
const f = fetch) or by string key (globalThis["fetch"]), which the sweep's pattern cannot see.
Checks: bun x tsc --noEmit is clean. The gate (bun scripts/gate.ts --fix) changed nothing and only noted long comment lines. The 13 test files covering the guard, discovery, OAuth and mirroring pass: 213 pass, 4 skipped because the sandbox cannot bind a unix socket; the forge's check runs those. scripts/fast.ts could not narrow the list because outbound.ts is in the diff, so I picked those 13 files myself.
The desk hold says production is rolling and to hold changes to trevato/forge. This push only updates the pull's branch and merges nothing, so I went ahead; landing it should wait until the release settles.
To try it: bun test test/outbound-sweep.test.ts test/outbound.test.ts
🤖 Generated with Claude Code
Earlier asks are met. NAT64 and 6to4 wrappers are now judged as the IPv4 address they carry, and NAT64 local-use is refused outright. Wrapped public addresses still pass, and there are tests for both. The sweep now catches globalThis./Bun./window./self. fetch, with a sample test. operatorAllowed is imported from origin_fetch.ts directly. I could not diff against 70dc013dae8e (the commit is not in the clone), so I read the full change. I did not open the preview or the screenshots; this pull has no web changes. Non-blocking: test/outbound-sweep.test.ts has two stacked doc comments above CALL, and the first is stale. Non-blocking: Teredo and fetch aliases are left out, and the pull says so.
The guard already existed in
src/kernel/outbound.ts, and it never follows a redirect. This pull adds a test that sweepssrc/for everyfetch(call, tightens the guard, and fixes the four calls the sweep found going around it.Calls fixed (they skipped the guard). When a member connects an origin, the host they type is vetted once, during discovery. These four calls then fetched that host again with a bare
fetch, so a name that answered public at discovery and private later (DNS rebinding) got through:registerClient(POST /oauth/register) insrc/origins/oauth.tspostForm(device and token exchange) insrc/origins/oauth.tsrevokeGrant(its URL comes from a GitHub EnterpriseapiUrlsomeone typed) insrc/origins/oauth.tsApiClientinsrc/origins/providers/http.tsAll four now go through
originFetchin the newsrc/origins/origin_fetch.ts. It sends every request throughoutboundFetchwith the admin's trusted host names. Hosts the operator allows inFORGE_ORIGIN_ALLOW, and loopback in dev, are still fetched directly. That exemption logic moved out ofdiscover.ts, which re-exportsoperatorAllowedsogit-mirror.tskeeps working.Guard changes in
outbound.ts.isIPchecks it. Spellings like2130706433,0x7f000001,0177.0.0.1and127.1count as the address they spell and never reach a resolver. Callers that pass a bare host, such as git, are covered too.::/96(the old IPv4-compatible form, e.g.::127.0.0.1) and240.0.0.0/4.New test,
test/outbound-sweep.test.ts.fetch(insrc/whose URL is not a literal (a same-origin path,127.0.0.1, or a named https host). Each one must be in an allow list, by file and count, with its reason; most reasons are operator configuration, the forge's own loopback or socket, or a LAN printer thatcore/devices.tsalready restricts to private addresses. Browser scripts undersrc/web/are exempt as a group, since they only fetch the forge's own pages.oauth.tsandproviders/http.tscontain no bare fetch. That assertion fails onmain.vetHostwith a resolver that always answers public, and throughoutboundFetchURLs: decimal, hex, octal, short form, mapped IPv6 in dotted and hex form, bracketed, IPv4-compatible,fe80::,fd00::, and the metadata address in several forms.169.254.169.254comes back as a 302 and is not followed.originFetchrefuses private origins outside dev and keeps the operator and dev exemptions.What to look at. The allow-list reasons come from reading each call site briefly. The ones least checked are
src/actions/cloud.ts,src/actions/pinned.ts,src/apps/proxy.tsandsrc/apps/preview_spec.ts. NAT64 (64:ff9b::/96) and 6to4 (2002::/16) addresses that wrap a private IPv4 are still not refused; that should be a follow-up issue.Checks. Gate (rewrapped comments committed),
bun x tsc --noEmit, and the 90 test files that touch the guard, origins, webhooks, git mirroring and CIDR parsing: 875 pass, 7 skipped, 0 fail.scripts/fast.tsreported the diff as too broad to name its tests, so I chose those files myself. I couldn't record a plan on the issue because thekeep_plantool wasn't available in this run.How to try it.
bun test test/outbound-sweep.test.ts. Then addawait fetch(someVar)to any server file insrc/and run it again: the sweep names the new line.🤖 Generated with Claude Code
Closes #14280