feat(edge)!: trust cf-connecting-ip only under trustProxy, for HTTP and WebSocket (CARD-23, #119)
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 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
8 files changed
+244
-10
No files matched your search
@@ -58,6 +58,13 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
constraints at a later segment of an otherwise unreachable route. The route then boots, as
|
||||
before.
|
||||
|
||||
- **Edge WebSocket upgrades no longer trust `cf-connecting-ip` by default** (#119). `edgeHandler`
|
||||
copied the header into `ctx.ip` on every upgrade, so any client that sent it chose its own
|
||||
address. It now counts only under `trustProxy: true`, the same rule HTTP follows. Without it,
|
||||
`ctx.ip` on an edge WebSocket is `''`, as it already was on edge HTTP: workerd exposes no peer
|
||||
address. An app behind Cloudflare that keys anything on the WebSocket IP needs
|
||||
`createApp({ trustProxy: true })`.
|
||||
|
||||
### Added
|
||||
|
||||
- **`limits.maxWsMessageBytes` and `limits.maxWsQueue`** (#107): per-connection bounds on inbound
|
||||
@@ -83,6 +90,13 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Edge HTTP fills `ctx.ip` from `cf-connecting-ip` under `trustProxy`** (#119). `edgeHandler`
|
||||
never read the header for HTTP, so IP-keyed plugins such as rate-limit saw `''`, one bucket for
|
||||
every client. Under `trustProxy: true` the header now sets `ctx.ip`, and it wins over
|
||||
`x-forwarded-for`, because Cloudflare sets it itself while XFF can carry hops the client supplied.
|
||||
Without `trustProxy` it is ignored. Only `edgeHandler` reads it: the Node, Deno and Bun adapters, and a
|
||||
bare `app.fetch`, ignore it as before.
|
||||
|
||||
- **`static` no longer serves files outside its root through a symlink** (#106). The traversal guard
|
||||
compared paths lexically, and the file read then followed symlinks, so `public/leak -> /etc/hosts`
|
||||
was served. Containment now compares real paths: the requested file, and a directory's
|
||||
|
||||
Reference in new issue
Block a user