fix(mesh): cap what an unauthenticated control peer can send on Node (#120) #157

Merged
chrnx merged 1 commits from fix/mesh-preauth-wire-cap into develop 2026-10-24 19:45:34 +00:00
Owner

Before a peer's hello is accepted, boundInbound refuses any frame over
64 KiB, but only once it has the whole frame. On Node, the control
channel's WebSocketServer takes the authenticated bound as its
maxPayload (about 7 MB at the defaults, so an RPC body fits), and
maxPayload is fixed per server. So ws assembled a frame up to that
size for a peer that had not yet authenticated. Found in the second
pre-freeze review. The existing pre-auth tests use a fake socket and
never reached ws's own limit.

The Node adapter now counts the raw socket bytes from the upgrade until
the hello is accepted (boundInbound gains an onWiden hook for that
moment). Past a hello's worth (64 KiB + 1 KiB), it sends close 1009, as
every runtime does for an oversized frame, pauses the socket so ws
reads nothing more, and ends it. The counter is installed in the
handleUpgrade callback, after ws attaches its own data listener,
so no chunk is lost.

Bun and Deno have no per-socket limit for this. The CHANGELOG #120 entry
now says so, and says to limit frame size at the proxy if untrusted
peers can reach a Bun or Deno teapot's control path.

Test: a raw client announces a 5 MB frame before its hello and sends
200 KiB of it. The teapot answers with a 1009 close frame and closes the
connection. Without the fix it waits for the rest of the frame.

Before a peer's hello is accepted, `boundInbound` refuses any frame over 64 KiB, but only once it has the whole frame. On Node, the control channel's `WebSocketServer` takes the authenticated bound as its `maxPayload` (about 7 MB at the defaults, so an RPC body fits), and `maxPayload` is fixed per server. So `ws` assembled a frame up to that size for a peer that had not yet authenticated. Found in the second pre-freeze review. The existing pre-auth tests use a fake socket and never reached `ws`'s own limit. The Node adapter now counts the raw socket bytes from the upgrade until the hello is accepted (`boundInbound` gains an `onWiden` hook for that moment). Past a hello's worth (64 KiB + 1 KiB), it sends close 1009, as every runtime does for an oversized frame, pauses the socket so `ws` reads nothing more, and ends it. The counter is installed in the `handleUpgrade` callback, after `ws` attaches its own `data` listener, so no chunk is lost. Bun and Deno have no per-socket limit for this. The CHANGELOG #120 entry now says so, and says to limit frame size at the proxy if untrusted peers can reach a Bun or Deno teapot's control path. Test: a raw client announces a 5 MB frame before its hello and sends 200 KiB of it. The teapot answers with a 1009 close frame and closes the connection. Without the fix it waits for the rest of the frame.
chrnx added 1 commit 2026-10-24 19:36:20 +00:00
fix(mesh): cap what an unauthenticated control peer can send on Node (#120)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 19s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 33s
411c7ef3f5
Before a peer's hello is accepted, `boundInbound` refuses any frame over
64 KiB, but only once it has the whole frame. On Node, the control
channel's `WebSocketServer` takes the authenticated bound as its
`maxPayload` (about 7 MB at the defaults, so an RPC body fits), and
`maxPayload` is fixed per server. So `ws` assembled a frame up to that
size for a peer that had not yet authenticated. Found in the second
pre-freeze review. The existing pre-auth tests use a fake socket and
never reached `ws`'s own limit.

The Node adapter now counts the raw socket bytes from the upgrade until
the hello is accepted (`boundInbound` gains an `onWiden` hook for that
moment). Past a hello's worth (64 KiB + 1 KiB), it sends close 1009, as
every runtime does for an oversized frame, pauses the socket so `ws`
reads nothing more, and ends it. The counter is installed in the
`handleUpgrade` callback, after `ws` attaches its own `data` listener,
so no chunk is lost.

Bun and Deno have no per-socket limit for this. The CHANGELOG #120 entry
now says so, and says to limit frame size at the proxy if untrusted
peers can reach a Bun or Deno teapot's control path.

Test: a raw client announces a 5 MB frame before its hello and sends
200 KiB of it. The teapot answers with a 1009 close frame and closes the
connection. Without the fix it waits for the rest of the frame.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit b1392db7af into develop 2026-10-24 19:45:34 +00:00
Sign in to join this conversation.