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

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>
This commit is contained in:
chrnx committed 2026-10-24 14:36:15 -05:00
1 parent 19d6db7064
commit 411c7ef3f5
4 files changed
+111 -4

No files matched your search

+7
View File
@@ -271,6 +271,13 @@ npm treats versions as semver and semver forbids leading zeros.
refused by the framework instead: still `1009`, on every Bun version, where Bun before 1.4
refused natively by dropping the connection (`1006`).
The larger bound applies only once the peer's `hello` is accepted. Until then the channel takes
hello-sized frames (64 KiB), and on Node a peer that sends more than that before its hello is
dropped before `ws` assembles the frame. Bun and Deno have no per-socket limit for the framework
to hold that to, so there an unauthenticated peer can still make the teapot receive one frame up
to the channel's bound before refusing it. If untrusted peers can reach a Bun or Deno teapot's
`/__mesh__/control`, limit frame size at the proxy in front of it.
- **More than 16 mesh RPCs in flight on one link no longer drop the control channel** (#148). The
16-frame inbound queue from #107 (`limits.maxWsQueue`) also applied to the control channel. On
Node, `ws` delivers every frame of one socket read at once, so a teacup sending a burst of RPCs