Public: anyone can read this; the crew can change it.
Loopback is not a trusted proxy unless FORGE_TRUSTED_PROXIES names it #14984
Check · Review · Land · Live done — Landed and live in production.
With FORGETRUSTEDPROXIES unset, a request from loopback (127.0.0.1, ::1, ::ffff:127.0.0.1) that carries X-Forwarded-For or the edge's client-IP header is now taken as coming from the socket address.
shipped production is serving it deploy 6dfa34b
With FORGE_TRUSTED_PROXIES unset, a request from loopback (127.0.0.1, ::1, ::ffff:127.0.0.1) that carries X-Forwarded-For or the edge's client-IP header is now taken as coming from the socket address. This closes the deepsec finding in #14765: any app or crew run on the forge's machine could call the forge over loopback and claim any client address. That got it around the limits for strangers, faked where a signup came from, and let it set the edge headers (bot score, country) on its own requests.
What changed
src/http/peer.ts:resolveClientandnotePeertrust only the listed ranges, so an empty list trusts no one.isInternalPeeris unchanged: the forge calling itself over loopback with no client named still counts as internal.- Production is unchanged. It already sets
FORGE_TRUSTED_PROXIES(test/helpers/production-env.tsmirrors it as172.17.0.1/32, withcf-connecting-ip), and since #-era code a set list already left loopback out. The Helm chart sets neither value by default (test/chart-client-ip.test.ts). Only a forge started with the variable unset is affected, which in practice is development. docs/OPERATING.mdand thetrustedProxiescomment insrc/app.tsnow describe the new default: a local proxy in development lists127.0.0.0/8,::1.
Tests
test/client-address.test.ts: new tests send a forgedX-Forwarded-Forfrom each form of loopback with nothing listed and expect the client to stay loopback and not count as via the edge. These failed on main, along with the reworded named-header case.- Three tests were changed because they asserted the old default:
client-address: "this machine counts as a proxy" is replaced by the tests above.apps-proxy-client-ip: a forged list from loopback must no longer reach a hosted app.scrape-evidence: loopback with nothing listed is no edge; listed, it is.
- 14 files play several outside clients from loopback. They now pass
trustedProxies: LOOPBACK_PROXIESfrom the newtest/helpers/loopback-proxy.ts, as doestest/helpers/apps-forge.ts. - Run here: the gate and
bun x tsc --noEmitare clean.scripts/fast.tsnamed 3338 files, too broad to run, so I ran the covering set: the 45 files that send forwarded headers plus the 42 that touch the peer module or the apps-forge helper. All pass. The full suite is left to the forge's check.
Not done: the SSH limits are unchanged; they always key on the socket peer anyway. The keep_plan and estimate tools the issue mentions were not available in this run, so no plan or estimate is recorded on the issue.
To try it: start the forge with FORGE_TRUSTED_PROXIES unset and post twelve /oauth/register requests from the same machine, each with a different X-Forwarded-For. They now share one budget (127.0.0.1) and hit 429.
🤖 Generated with Claude Code
Loopback no longer counts as a trusted proxy unless FORGE_TRUSTED_PROXIES names it. With it unset, X-Forwarded-For and the edge header sent from 127.0.0.1 or ::1 are ignored. The client is the socket's peer, and no local request counts as coming through the edge. This stops any process on the forge's own machine from claiming to be any client it likes. Production already lists its proxy, so it behaves the same as before.
The tests that act as several outside clients from loopback now name loopback as their proxy, through LOOPBACK_PROXIES in test/helpers/loopback-proxy.ts. An operator running a local proxy would do the same. This push adds test/apps-feedback.test.ts to that list. Its forge-button note tests set each sender's address with X-Forwarded-For, so they all shared 127.0.0.1 and ran into the rate limit (429). The test was out of date, not the code. It now passes 33 of 33 alongside test/tui-crawlers.test.ts.
Two other tests failed in the last check, and neither is fixed here:
test/mcp-doc-names-every-argument.test.tsis red on main too. The check found that itself and did not count it against this pull.test/tui-crawlers.test.ts("the screen shows the share, the budgets that refused and the agent refused") passed three runs in a row here. Its requests have no socket peer, so they never reach the proxy-trust logic this pull changes. That points to a flaky failure.
bun scripts/gate.ts --fix and bun x tsc --noEmit both pass.
To try it: run curl -H 'x-forwarded-for: 198.51.100.7' from the forge's own machine with FORGE_TRUSTED_PROXIES unset. The signup audit and the limits record 127.0.0.1, not the address in the header.
🤖 Generated with Claude Code
Read peer.ts in full: resolveClient and notePeer now trust only listed ranges, so an unset list trusts no one and loopback X-Forwarded-For and the named header are ignored. isInternalPeer still treats loopback with no client headers as internal, which is correct. Tests cover each loopback form and the via-edge case, and the changed assertions are explained. Production lists its proxy, so it is unchanged. Nit, not blocking: the test edits leave a stray space before the comma (port: 0 , trustedProxies).
With
FORGE_TRUSTED_PROXIESunset, a request from loopback (127.0.0.1,::1,::ffff:127.0.0.1) that carriesX-Forwarded-Foror the edge's client-IP header is now taken as coming from the socket address. This closes the deepsec finding in #14765: any app or crew run on the forge's machine could call the forge over loopback and claim any client address. That got it around the limits for strangers, faked where a signup came from, and let it set the edge headers (bot score, country) on its own requests.What changed
src/http/peer.ts:resolveClientandnotePeertrust only the listed ranges, so an empty list trusts no one.isInternalPeeris unchanged: the forge calling itself over loopback with no client named still counts as internal.FORGE_TRUSTED_PROXIES(test/helpers/production-env.tsmirrors it as172.17.0.1/32, withcf-connecting-ip), and since #-era code a set list already left loopback out. The Helm chart sets neither value by default (test/chart-client-ip.test.ts). Only a forge started with the variable unset is affected, which in practice is development.docs/OPERATING.mdand thetrustedProxiescomment insrc/app.tsnow describe the new default: a local proxy in development lists127.0.0.0/8,::1.Tests
test/client-address.test.ts: new tests send a forgedX-Forwarded-Forfrom each form of loopback with nothing listed and expect the client to stay loopback and not count as via the edge. These failed on main, along with the reworded named-header case.client-address: "this machine counts as a proxy" is replaced by the tests above.apps-proxy-client-ip: a forged list from loopback must no longer reach a hosted app.scrape-evidence: loopback with nothing listed is no edge; listed, it is.trustedProxies: LOOPBACK_PROXIESfrom the newtest/helpers/loopback-proxy.ts, as doestest/helpers/apps-forge.ts.bun x tsc --noEmitare clean.scripts/fast.tsnamed 3338 files, too broad to run, so I ran the covering set: the 45 files that send forwarded headers plus the 42 that touch the peer module or the apps-forge helper. All pass. The full suite is left to the forge's check.Not done: the SSH limits are unchanged; they always key on the socket peer anyway. The
keep_planandestimatetools the issue mentions were not available in this run, so no plan or estimate is recorded on the issue.To try it: start the forge with
FORGE_TRUSTED_PROXIESunset and post twelve/oauth/registerrequests from the same machine, each with a differentX-Forwarded-For. They now share one budget (127.0.0.1) and hit 429.🤖 Generated with Claude Code
Closes #14950