serveDeno and serveBun know the client's socket address but never give it to HTTP requests. ctx.ip is therefore always '' on those runtimes unless trustProxy is on, and with trustProxy it can only come from x-forwarded-for.
src/deno.ts: the WebSocket branch passes info.remoteAddr.hostname to toWsRequest, but the HTTP branch calls app.fetch(request) and drops info.
src/bun.ts: the same pattern. server.requestIP(request) feeds the WebSocket path, and HTTP gets a bare app.fetch(request).
src/http/web.ts (~L246): the fetch path sets ip from x-forwarded-for when trustProxy is on, and to '' otherwise. The comment says "there's no socket peer address to fall back to on the fetch path". That is true for a bare app.fetch, but not when core's own adapter owns the server.
Node's listen() does not have this problem: deriveIp falls back to req.socket.remoteAddress.
Impact
Anything that keys on ctx.ip breaks silently on Deno and Bun. The worst case is @green-tea/rate-limit. Its default keyOf folds '' into one unknown bucket, so every client shares one counter per rule. A single caller who spends a sign-in limit (5 per 15 minutes) locks out every user. The fail-closed behavior turns a brute-force guard into a denial-of-service lever.
The plugin README mentions that ip is empty through app.fetch(), but it is just as empty through serveDeno/serveBun, which are the supported way to serve on those runtimes.
Found while integrating @green-tea/rate-limit on Deno in a downstream migration. The workaround there is to deploy behind a proxy with trustProxy: true.
Expected
On Deno and Bun, ctx.ip should be the socket peer address, with x-forwarded-for taking over only when trustProxy is on, the same as Node's deriveIp.
Suggested direction
Let the adapters pass the peer address into the fetch path. For example, an internal app.fetch(request, { remoteAddr }) (or a non-public symbol) that web.ts uses as the untrusted fallback in place of ''. Plain app.fetch(request) from a user-owned server keeps today's behavior.
Acceptance
serveDeno and serveBun produce a non-empty ctx.ip for a socket client, both with and without trustProxy.
With trustProxy, x-forwarded-for's first hop wins. Without it, a spoofed x-forwarded-for is ignored.
A test per adapter, plus a rate-limit regression: two clients get separate buckets on Deno.
## Problem
`serveDeno` and `serveBun` know the client's socket address but never give it to HTTP requests. `ctx.ip` is therefore always `''` on those runtimes unless `trustProxy` is on, and with `trustProxy` it can only come from `x-forwarded-for`.
- `src/deno.ts`: the WebSocket branch passes `info.remoteAddr.hostname` to `toWsRequest`, but the HTTP branch calls `app.fetch(request)` and drops `info`.
- `src/bun.ts`: the same pattern. `server.requestIP(request)` feeds the WebSocket path, and HTTP gets a bare `app.fetch(request)`.
- `src/http/web.ts` (~L246): the fetch path sets `ip` from `x-forwarded-for` when `trustProxy` is on, and to `''` otherwise. The comment says *"there's no socket peer address to fall back to on the fetch path"*. That is true for a bare `app.fetch`, but not when core's own adapter owns the server.
Node's `listen()` does not have this problem: `deriveIp` falls back to `req.socket.remoteAddress`.
## Impact
Anything that keys on `ctx.ip` breaks silently on Deno and Bun. The worst case is `@green-tea/rate-limit`. Its default `keyOf` folds `''` into one `unknown` bucket, so **every client shares one counter per rule**. A single caller who spends a sign-in limit (5 per 15 minutes) locks out every user. The fail-closed behavior turns a brute-force guard into a denial-of-service lever.
The plugin README mentions that `ip` is empty through `app.fetch()`, but it is just as empty through `serveDeno`/`serveBun`, which are the supported way to serve on those runtimes.
## Repro (Deno, core 26.9.0-beta.2)
```ts
@Route('/') class C { @Get('/ip') ip(@needs('req') req: { ip: string }) { return { ip: req.ip }; } }
@Module({ mountpoint: '/', controllers: [C] }) class M {}
await serveDeno(createApp({ modules: [M] }), { port: 4000 });
// curl localhost:4000/ip → {"ip":""}
```
Found while integrating `@green-tea/rate-limit` on Deno in a downstream migration. The workaround there is to deploy behind a proxy with `trustProxy: true`.
## Expected
On Deno and Bun, `ctx.ip` should be the socket peer address, with `x-forwarded-for` taking over only when `trustProxy` is on, the same as Node's `deriveIp`.
## Suggested direction
Let the adapters pass the peer address into the fetch path. For example, an internal `app.fetch(request, { remoteAddr })` (or a non-public symbol) that `web.ts` uses as the untrusted fallback in place of `''`. Plain `app.fetch(request)` from a user-owned server keeps today's behavior.
## Acceptance
- `serveDeno` and `serveBun` produce a non-empty `ctx.ip` for a socket client, both with and without `trustProxy`.
- With `trustProxy`, `x-forwarded-for`'s first hop wins. Without it, a spoofed `x-forwarded-for` is ignored.
- A test per adapter, plus a rate-limit regression: two clients get separate buckets on Deno.
chrnx
added the bug label 2026-10-06 02:05:21 +00:00
Fixed in 26.11.0-rc.1 (b86cd60, f78c9dc). From the changelog:
serveDeno() and serveBun() populate ctx.ip with the client's address (#116). The fetch path had no way to learn the socket peer, so every HTTP request on Deno and Bun saw ctx.ip as '', and anything keyed on it put every client in one bucket — the rate-limit plugin, where one client could exhaust the limit for everyone, above all. Both adapters now hand the peer to app.fetch, and ctx.ip follows the same rule as Node's listen(): the first x-forwarded-for hop when trustProxy is on and the header is present, the socket peer otherwise. That includes trustProxy with no x-forwarded-for, which used to answer '' on the fetch path and now falls back to the peer, as Node always has. Addresses are passed through as each runtime reports them, so the IPv6 loopback is ::1 on all three but Node may report an IPv4 client as ::ffff:127.0.0.1. A bare app.fetch(request) from your own code has no socket to report and still answers '' (or the forwarded hop), and so does a Request copied from the one the adapter received. No signature changed. The edge adapter is unchanged: trusting cf-connecting-ip is only correct behind Cloudflare, and needs its own decision.
Fixed in **26.11.0-rc.1** (`b86cd60`, `f78c9dc`). From the changelog:
- **`serveDeno()` and `serveBun()` populate `ctx.ip` with the client's address** (#116). The fetch path had no way to learn the socket peer, so every HTTP request on Deno and Bun saw `ctx.ip` as `''`, and anything keyed on it put every client in one bucket — the rate-limit plugin, where one client could exhaust the limit for everyone, above all. Both adapters now hand the peer to `app.fetch`, and `ctx.ip` follows the same rule as Node's `listen()`: the first `x-forwarded-for` hop when `trustProxy` is on and the header is present, the socket peer otherwise. That includes `trustProxy` with no `x-forwarded-for`, which used to answer `''` on the fetch path and now falls back to the peer, as Node always has. Addresses are passed through as each runtime reports them, so the IPv6 loopback is `::1` on all three but Node may report an IPv4 client as `::ffff:127.0.0.1`. A bare `app.fetch(request)` from your own code has no socket to report and still answers `''` (or the forwarded hop), and so does a `Request` copied from the one the adapter received. No signature changed. The edge adapter is unchanged: trusting `cf-connecting-ip` is only correct behind Cloudflare, and needs its own decision.
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.
Problem
serveDenoandserveBunknow the client's socket address but never give it to HTTP requests.ctx.ipis therefore always''on those runtimes unlesstrustProxyis on, and withtrustProxyit can only come fromx-forwarded-for.src/deno.ts: the WebSocket branch passesinfo.remoteAddr.hostnametotoWsRequest, but the HTTP branch callsapp.fetch(request)and dropsinfo.src/bun.ts: the same pattern.server.requestIP(request)feeds the WebSocket path, and HTTP gets a bareapp.fetch(request).src/http/web.ts(~L246): the fetch path setsipfromx-forwarded-forwhentrustProxyis on, and to''otherwise. The comment says "there's no socket peer address to fall back to on the fetch path". That is true for a bareapp.fetch, but not when core's own adapter owns the server.Node's
listen()does not have this problem:deriveIpfalls back toreq.socket.remoteAddress.Impact
Anything that keys on
ctx.ipbreaks silently on Deno and Bun. The worst case is@green-tea/rate-limit. Its defaultkeyOffolds''into oneunknownbucket, so every client shares one counter per rule. A single caller who spends a sign-in limit (5 per 15 minutes) locks out every user. The fail-closed behavior turns a brute-force guard into a denial-of-service lever.The plugin README mentions that
ipis empty throughapp.fetch(), but it is just as empty throughserveDeno/serveBun, which are the supported way to serve on those runtimes.Repro (Deno, core 26.9.0-beta.2)
Found while integrating
@green-tea/rate-limiton Deno in a downstream migration. The workaround there is to deploy behind a proxy withtrustProxy: true.Expected
On Deno and Bun,
ctx.ipshould be the socket peer address, withx-forwarded-fortaking over only whentrustProxyis on, the same as Node'sderiveIp.Suggested direction
Let the adapters pass the peer address into the fetch path. For example, an internal
app.fetch(request, { remoteAddr })(or a non-public symbol) thatweb.tsuses as the untrusted fallback in place of''. Plainapp.fetch(request)from a user-owned server keeps today's behavior.Acceptance
serveDenoandserveBunproduce a non-emptyctx.ipfor a socket client, both with and withouttrustProxy.trustProxy,x-forwarded-for's first hop wins. Without it, a spoofedx-forwarded-foris ignored.Fixed in 26.11.0-rc.1 (
b86cd60,f78c9dc). From the changelog:serveDeno()andserveBun()populatectx.ipwith the client's address (#116). The fetch path had no way to learn the socket peer, so every HTTP request on Deno and Bun sawctx.ipas'', and anything keyed on it put every client in one bucket — the rate-limit plugin, where one client could exhaust the limit for everyone, above all. Both adapters now hand the peer toapp.fetch, andctx.ipfollows the same rule as Node'slisten(): the firstx-forwarded-forhop whentrustProxyis on and the header is present, the socket peer otherwise. That includestrustProxywith nox-forwarded-for, which used to answer''on the fetch path and now falls back to the peer, as Node always has. Addresses are passed through as each runtime reports them, so the IPv6 loopback is::1on all three but Node may report an IPv4 client as::ffff:127.0.0.1. A bareapp.fetch(request)from your own code has no socket to report and still answers''(or the forwarded hop), and so does aRequestcopied from the one the adapter received. No signature changed. The edge adapter is unchanged: trustingcf-connecting-ipis only correct behind Cloudflare, and needs its own decision.