fix(mesh): hold the control channel to hello size until the peer authenticates
boundInbound(socket, meshBounds) runs before ensureBooted() and before the hello is checked, and meshBounds allowed 4,096 queued frames of up to 7 MB each. During a slow boot nothing reads that queue, so an unauthenticated peer could make the process buffer tens of GB. The control channel's bounds are now phased (controlBounds() replaces controlLimits()): - until the hello is accepted: frames of at most HELLO_FRAME_BYTES (64 KiB) and the default 16-frame queue, so about 1 MiB per connection; - after: the frame bound from #120 and the queue bound from #148. boundInbound takes the second set as an optional `widened` argument and keeps the switch on the bounded socket under a Symbol.for key. The teapot calls widenInbound() when the handshake succeeds. The teapot's own parse check follows the same phases, so a standalone createMeshControl also refuses a pre-auth frame over hello size. This is an auth-phased bound rather than a total-bytes cap: the only unauthenticated frame with a purpose is the hello, and phasing keeps the trusted path free of a second accounting rule. No new option. On Node the control path's native maxPayload stays at the authed bound, because ws cannot change it per phase. A pre-auth peer can still make ws assemble one frame of up to that size before boundInbound closes the connection with 1009. That frame is transient and never queued. Tests: during a delayed boot, a 1 MB pre-auth frame closes 1009 at once and a flood closes 1013 within 17 frames; after the hello, large frames and a 64-ping burst are accepted. On Node, Deno and Bun, an unauthenticated 1 MB frame over a real socket closes 1009. The #148 64-RPC test stays green. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
9 files changed
+231
-35
No files matched your search
@@ -251,6 +251,12 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
more than one socket read can carry. User `@Ws` routes keep closing `1013` at `maxWsQueue`. Deno
|
||||
and Bun deliver frames one at a time and did not hit this, but they now share the same bound.
|
||||
|
||||
Both larger bounds, this one and the frame size from #120, **apply only once the peer's `hello`
|
||||
is accepted**. Until then the control channel takes frames of at most 64 KiB and queues at most
|
||||
16, and closes with `1009` or `1013` past that. An unauthenticated peer can therefore make a
|
||||
teapot hold about 1 MiB per connection, including while `app.upgrade` waits for a slow boot,
|
||||
instead of thousands of multi-megabyte frames.
|
||||
|
||||
- **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
|
||||
|
||||
Reference in new issue
Block a user