CARD-23, decision D21, core issue #119. Before this change, edgeHandler copied cf-connecting-ip into ctx.ip on every WebSocket upgrade, so any client chose its own address, and it never read the header for HTTP, where IP-keyed plugins saw ''. Now the header counts only under trustProxy, on both paths, and there is no new option.
How. The adapter can't decide on its own, because trustProxy is an app option. So:
src/edge.ts: edgeHandler records the header against the object it hands the app: the Request for HTTP, the WsRequest for an upgrade, whose ip now starts as ''. One helper, recordClient, serves both paths.
src/http/peer.ts: a second internal registry, next to the #116 peer one, with the same globalThis symbol registration because @green-tea/core/edge is its own bundle. trustedProxyClient(source, trustProxy) returns '' unless trustProxy is on. This is the single check both paths use.
src/http/web.ts (app.fetch): trustedProxyClient(...) || x-forwarded-for (trusted) || peer, so the header beats XFF under trustProxy (rule 3).
src/app/index.ts (app.upgrade): the same check overrides the WsRequest.ip when present. buildAppUpgrade (internal) now takes { limits, trustProxy }.
Nothing else writes to the registry, so Node, Deno, Bun, and a bare app.fetch/app.upgrade ignore the header as before (T6).
CHANGELOG.md: ### Breaking (edge WS) and ### Fixed (edge HTTP).
No public API changed: peer.ts isn't exported, and App/types.ts are unchanged.
Tests
test/edge-client-ip.test.ts (Node/Vitest): T1–T3 through edgeHandler itself; T4/T5 through app.upgrade with the value recorded the way edgeHandler records it; T6 through the Node listener (cf-connecting-ip ignored, peer IP kept). Also covers: a bare app.fetch/app.upgrade ignoring the header, XFF still applying without the header, and an adapter-supplied WS ip passing through. Against the old src, T1, T2, T4 and T5 fail.
test/edge/run.ts + worker.ts (real workerd via Miniflare): T1–T5 end to end, including the real WebSocketPair upgrade, with a trusted host for a trustProxy: true app. Against the old src this fails at T1.
Rebased on origin/develop after #134 and #135 merged.npm audit --audit-level=moderate passes locally on this branch now, and the Bun close-code tests are fixed on develop. Local checks were re-run after the rebase with the same results.
Unsure about
WS + x-forwarded-for: under trustProxy without cf-connecting-ip, an edge WS upgrade still gets ''. WS never derived XFF (a comment in buildWsRoutes marks that out of scope), and the card doesn't ask for it, so I didn't widen the scope.
Cloudflare without edgeHandler: an app deployed as { fetch: app.fetch } directly doesn't get the header, because only edgeHandler records it. I treated this as the conservative reading of "edge-only".
The registry is keyed by object identity. A Request copied before it reaches app.fetch loses the value, the same property the #116 peer registry has (and tests).
Docs follow-up (CARD-12)
Edge/deploy guide: ctx.ip on Cloudflare comes from cf-connecting-ip only with createApp({ trustProxy: true }), for HTTP and WebSocket. It takes precedence over XFF. Without trustProxy it is ''.
Rate-limit plugin edge docs: mention trustProxy (otherwise all clients share one bucket).
Migration note: edge WebSocket apps that relied on the header now need trustProxy: true.
## What and why
CARD-23, decision D21, core issue #119. Before this change, `edgeHandler` copied `cf-connecting-ip` into `ctx.ip` on **every** WebSocket upgrade, so any client chose its own address, and it never read the header for HTTP, where IP-keyed plugins saw `''`. Now the header counts **only under `trustProxy`**, on both paths, and there is no new option.
**How.** The adapter can't decide on its own, because `trustProxy` is an app option. So:
- `src/edge.ts`: `edgeHandler` records the header against the object it hands the app: the `Request` for HTTP, the `WsRequest` for an upgrade, whose `ip` now starts as `''`. One helper, `recordClient`, serves both paths.
- `src/http/peer.ts`: a second internal registry, next to the #116 peer one, with the same `globalThis` symbol registration because `@green-tea/core/edge` is its own bundle. `trustedProxyClient(source, trustProxy)` returns `''` unless `trustProxy` is on. This is the single check both paths use.
- `src/http/web.ts` (`app.fetch`): `trustedProxyClient(...) || x-forwarded-for (trusted) || peer`, so the header beats XFF under `trustProxy` (rule 3).
- `src/app/index.ts` (`app.upgrade`): the same check overrides the `WsRequest.ip` when present. `buildAppUpgrade` (internal) now takes `{ limits, trustProxy }`.
- Nothing else writes to the registry, so Node, Deno, Bun, and a bare `app.fetch`/`app.upgrade` ignore the header as before (T6).
- `CHANGELOG.md`: `### Breaking` (edge WS) and `### Fixed` (edge HTTP).
No public API changed: `peer.ts` isn't exported, and `App`/`types.ts` are unchanged.
## Tests
- `test/edge-client-ip.test.ts` (Node/Vitest): T1–T3 through `edgeHandler` itself; T4/T5 through `app.upgrade` with the value recorded the way `edgeHandler` records it; T6 through the Node listener (`cf-connecting-ip` ignored, peer IP kept). Also covers: a bare `app.fetch`/`app.upgrade` ignoring the header, XFF still applying without the header, and an adapter-supplied WS `ip` passing through. Against the old `src`, T1, T2, T4 and T5 fail.
- `test/edge/run.ts` + `worker.ts` (real workerd via Miniflare): T1–T5 end to end, including the real `WebSocketPair` upgrade, with a `trusted` host for a `trustProxy: true` app. Against the old `src` this fails at T1.
| Check | Result |
|---|---|
| `npm run lint` | 0 errors (50 existing `no-explicit-any` warnings, unchanged) |
| `npm run format:check` | pass |
| `npm run typecheck` | pass |
| `npm test` | 925 passed |
| `npm run build` | pass |
| `npm run complexity:check` | every function ≤ 25 |
| `npm run test:deno` | 36 passed, 0 failed |
| `npm run test:bun` | 26 pass, 0 fail |
| `npm run test:edge` | PASS (incl. CARD-23 cases, router parity 1158 + 55) |
No frozen router-parity capture changed.
**Rebased on `origin/develop` after #134 and #135 merged.** `npm audit --audit-level=moderate` passes locally on this branch now, and the Bun close-code tests are fixed on develop. Local checks were re-run after the rebase with the same results.
## Unsure about
- **WS + `x-forwarded-for`:** under `trustProxy` without `cf-connecting-ip`, an edge WS upgrade still gets `''`. WS never derived XFF (a comment in `buildWsRoutes` marks that out of scope), and the card doesn't ask for it, so I didn't widen the scope.
- **Cloudflare without `edgeHandler`:** an app deployed as `{ fetch: app.fetch }` directly doesn't get the header, because only `edgeHandler` records it. I treated this as the conservative reading of "edge-only".
- The registry is keyed by object identity. A `Request` copied before it reaches `app.fetch` loses the value, the same property the #116 peer registry has (and tests).
## Docs follow-up (CARD-12)
- Edge/deploy guide: `ctx.ip` on Cloudflare comes from `cf-connecting-ip` only with `createApp({ trustProxy: true })`, for HTTP and WebSocket. It takes precedence over XFF. Without `trustProxy` it is `''`.
- Rate-limit plugin edge docs: mention `trustProxy` (otherwise all clients share one bucket).
- Migration note: edge WebSocket apps that relied on the header now need `trustProxy: true`.
Owner decisions (2026-10-23): both edge cases accepted as implemented: WS with no cf-connecting-ip keeps ip === '', and a bare app.fetch ignores the header (documented). Not merging yet: implementation review first.
Owner decisions (2026-10-23): both edge cases accepted as implemented: WS with no `cf-connecting-ip` keeps `ip === ''`, and a bare `app.fetch` ignores the header (documented). Not merging yet: implementation review first.
edgeHandler copied cf-connecting-ip into ctx.ip on every WebSocket
upgrade, so any client that sent the header chose its own address, and
it never read the header for HTTP, so IP-keyed plugins saw '' there.
D21 settles both: the header counts only under trustProxy, on both
paths, with no new option.
The adapter cannot make that call, because trustProxy is an app option.
So edgeHandler records the header against the object it hands the app
(the Request for HTTP, the WsRequest for an upgrade) in an internal
registry next to the Deno/Bun peer one, and app.fetch and app.upgrade
both consult it through one helper, trustedProxyClient(), which returns
'' unless trustProxy is on. Under trustProxy it takes precedence over
x-forwarded-for, since Cloudflare sets it itself and XFF can carry
client-supplied hops.
Nothing else records into the registry, so the Node, Deno and Bun
adapters, and a bare app.fetch or app.upgrade, ignore the header as
before.
BREAKING CHANGE: an edge WebSocket upgrade no longer takes ctx.ip from
cf-connecting-ip unless the app sets trustProxy: true; without it,
ctx.ip is ''.
Refs: #119
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What and why
CARD-23, decision D21, core issue #119. Before this change,
edgeHandlercopiedcf-connecting-ipintoctx.ipon every WebSocket upgrade, so any client chose its own address, and it never read the header for HTTP, where IP-keyed plugins saw''. Now the header counts only undertrustProxy, on both paths, and there is no new option.How. The adapter can't decide on its own, because
trustProxyis an app option. So:src/edge.ts:edgeHandlerrecords the header against the object it hands the app: theRequestfor HTTP, theWsRequestfor an upgrade, whoseipnow starts as''. One helper,recordClient, serves both paths.src/http/peer.ts: a second internal registry, next to the #116 peer one, with the sameglobalThissymbol registration because@green-tea/core/edgeis its own bundle.trustedProxyClient(source, trustProxy)returns''unlesstrustProxyis on. This is the single check both paths use.src/http/web.ts(app.fetch):trustedProxyClient(...) || x-forwarded-for (trusted) || peer, so the header beats XFF undertrustProxy(rule 3).src/app/index.ts(app.upgrade): the same check overrides theWsRequest.ipwhen present.buildAppUpgrade(internal) now takes{ limits, trustProxy }.app.fetch/app.upgradeignore the header as before (T6).CHANGELOG.md:### Breaking(edge WS) and### Fixed(edge HTTP).No public API changed:
peer.tsisn't exported, andApp/types.tsare unchanged.Tests
test/edge-client-ip.test.ts(Node/Vitest): T1–T3 throughedgeHandleritself; T4/T5 throughapp.upgradewith the value recorded the wayedgeHandlerrecords it; T6 through the Node listener (cf-connecting-ipignored, peer IP kept). Also covers: a bareapp.fetch/app.upgradeignoring the header, XFF still applying without the header, and an adapter-supplied WSippassing through. Against the oldsrc, T1, T2, T4 and T5 fail.test/edge/run.ts+worker.ts(real workerd via Miniflare): T1–T5 end to end, including the realWebSocketPairupgrade, with atrustedhost for atrustProxy: trueapp. Against the oldsrcthis fails at T1.npm run lintno-explicit-anywarnings, unchanged)npm run format:checknpm run typechecknpm testnpm run buildnpm run complexity:checknpm run test:denonpm run test:bunnpm run test:edgeNo frozen router-parity capture changed.
Rebased on
origin/developafter #134 and #135 merged.npm audit --audit-level=moderatepasses locally on this branch now, and the Bun close-code tests are fixed on develop. Local checks were re-run after the rebase with the same results.Unsure about
x-forwarded-for: undertrustProxywithoutcf-connecting-ip, an edge WS upgrade still gets''. WS never derived XFF (a comment inbuildWsRoutesmarks that out of scope), and the card doesn't ask for it, so I didn't widen the scope.edgeHandler: an app deployed as{ fetch: app.fetch }directly doesn't get the header, because onlyedgeHandlerrecords it. I treated this as the conservative reading of "edge-only".Requestcopied before it reachesapp.fetchloses the value, the same property the #116 peer registry has (and tests).Docs follow-up (CARD-12)
ctx.ipon Cloudflare comes fromcf-connecting-iponly withcreateApp({ trustProxy: true }), for HTTP and WebSocket. It takes precedence over XFF. WithouttrustProxyit is''.trustProxy(otherwise all clients share one bucket).trustProxy: true.d0869788a5to7fd5d7492e7fd5d7492etoa4245458c3Owner decisions (2026-10-23): both edge cases accepted as implemented: WS with no
cf-connecting-ipkeepsip === '', and a bareapp.fetchignores the header (documented). Not merging yet: implementation review first.a4245458c3to88cbe41f72