Edge HTTP ignores cf-connecting-ip: ctx.ip is empty on workerd #119

Closed
opened 2026-10-10 16:55:48 +00:00 by chrnx · 2 comments
Owner

On the edge adapter, cf-connecting-ip is only used for WebSocket upgrades (src/edge.ts:33). HTTP requests leave ctx.ip as '', or the x-forwarded-for value under trustProxy. That is the same symptom #116 fixed for Deno and Bun: IP-keyed plugins such as rate-limit put every caller in one bucket.

This was left out of #116 on purpose. Trusting cf-connecting-ip is only correct behind Cloudflare, because elsewhere any client can set the header. It needs a decision first:

  • trust it always on the edge adapter;
  • trust it only under trustProxy;
  • or add an explicit opt-in.

Whichever is chosen, WebSocket upgrades should behave the same way. Today they trust the header unconditionally.

On the edge adapter, `cf-connecting-ip` is only used for WebSocket upgrades (`src/edge.ts:33`). HTTP requests leave `ctx.ip` as `''`, or the `x-forwarded-for` value under `trustProxy`. That is the same symptom #116 fixed for Deno and Bun: IP-keyed plugins such as rate-limit put every caller in one bucket. This was left out of #116 on purpose. Trusting `cf-connecting-ip` is only correct behind Cloudflare, because elsewhere any client can set the header. It needs a decision first: - trust it always on the edge adapter; - trust it only under `trustProxy`; - or add an explicit opt-in. Whichever is chosen, WebSocket upgrades should behave the same way. Today they trust the header unconditionally.
Author
Owner

Merged into develop in #139 (CARD-23, FPRD-001c, 2026-10-23). Left open until the 1c acceptance gate (CARD-22), per the 1a/1b convention.

Merged into develop in #139 (CARD-23, FPRD-001c, 2026-10-23). Left open until the 1c acceptance gate (CARD-22), per the 1a/1b convention.
Author
Owner

Fixed in 26.11.0-rc.1 (88cbe41). From the changelog:

  • 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 }).

  • 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.

Fixed in **26.11.0-rc.1** (`88cbe41`). From the changelog: - **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 })`. - **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.
chrnx closed this issue 2026-11-18 01:04:11 +00:00
Sign in to join this conversation.