security: WebSocket input has no size or queue limit #107

Closed
opened 2026-09-25 14:02:13 +00:00 by chrnx · 1 comment
Owner

Kept internal under SECURITY.md: this one is exploitable. The GitHub advisory goes out with the fix.

Two missing limits, one effect: memory grows without bound while a client keeps sending.

  • The Node WebSocketServer is created without maxPayload (src/http/ws.ts:103), so one frame can be as large as the client wants. The ws default is 100 MiB.
  • Inbound messages go into a channel() with no buffer (src/http/ws.ts:67), and the default is Infinity (src/channel.ts:87). A client that sends faster than the handler reads builds an unbounded queue.

Fix: a maxPayload default (1 MiB, matching maxBodyBytes) and a bounded inbound queue, both configurable. On overflow, close the socket with 1009 rather than silently dropping messages the handler never sees. This adds options, so it must land before rc.1. Test: an oversized frame closes the socket with 1009, and a flood against a stalled handler keeps memory flat.

Kept internal under SECURITY.md: this one is exploitable. The GitHub advisory goes out with the fix. Two missing limits, one effect: memory grows without bound while a client keeps sending. - The Node `WebSocketServer` is created without `maxPayload` (src/http/ws.ts:103), so one frame can be as large as the client wants. The `ws` default is 100 MiB. - Inbound messages go into a `channel()` with no `buffer` (src/http/ws.ts:67), and the default is `Infinity` (src/channel.ts:87). A client that sends faster than the handler reads builds an unbounded queue. **Fix:** a `maxPayload` default (1 MiB, matching `maxBodyBytes`) and a bounded inbound queue, both configurable. On overflow, close the socket with 1009 rather than silently dropping messages the handler never sees. This adds options, so it must land **before** rc.1. **Test:** an oversized frame closes the socket with 1009, and a flood against a stalled handler keeps memory flat.
chrnx added the breaking changebugsecurity labels 2026-09-25 16:06:53 +00:00
Author
Owner

Fixed in 26.11.0-rc.1 (cad8122, 713122d, 69bdc8a). From the changelog:

  • Inbound WebSocket messages are capped at 1 MiB by default (#107). Node used ws's own default of 100 MiB, and Deno, Bun and the edge applied no cap of their own, so one client could make the server hold a message of any size the runtime would accept. A larger message now closes the connection with 1009 (message too large). Raise it with limits.maxWsMessageBytes.

  • A connection with 16 unread inbound messages is closed on the 17th (#107), with 1013 (inbound queue full). The queue behind inbound was unbounded on every runtime, so a handler that read slowly — or never — let a client grow it without limit. This also reaches a @Ws handler that never reads inbound at all: on Node those frames used to be discarded, and they now count. Raise the bound with limits.maxWsQueue.

  • limits.maxWsMessageBytes and limits.maxWsQueue (#107): per-connection bounds on inbound WebSocket messages, in bytes and in unread messages, server-wide on every runtime. createApp throws a TypeError for anything but a positive integer. Node and Bun refuse an oversized message before buffering it; Bun before 1.4 does so by dropping the connection, so its peer sees 1006 rather than 1009 (Bun 1.4 and later send 1009). Deno and workerd expose no such option, so there the message is received in full and then refused, and its memory is bounded by the platform's own cap. Worst-case buffered inbound memory is about maxConnections × maxWsQueue × maxWsMessageBytes, ≈ 15.6 GiB at the Node defaults; Deno and Bun have no connection cap, so set one at the platform or proxy there.

Fixed in **26.11.0-rc.1** (`cad8122`, `713122d`, `69bdc8a`). From the changelog: - **Inbound WebSocket messages are capped at 1 MiB by default** (#107). Node used `ws`'s own default of 100 MiB, and Deno, Bun and the edge applied no cap of their own, so one client could make the server hold a message of any size the runtime would accept. A larger message now closes the connection with `1009` (`message too large`). Raise it with `limits.maxWsMessageBytes`. - **A connection with 16 unread inbound messages is closed on the 17th** (#107), with `1013` (`inbound queue full`). The queue behind `inbound` was unbounded on every runtime, so a handler that read slowly — or never — let a client grow it without limit. This also reaches a `@Ws` handler that never reads `inbound` at all: on Node those frames used to be discarded, and they now count. Raise the bound with `limits.maxWsQueue`. - **`limits.maxWsMessageBytes` and `limits.maxWsQueue`** (#107): per-connection bounds on inbound WebSocket messages, in bytes and in unread messages, server-wide on every runtime. `createApp` throws a `TypeError` for anything but a positive integer. Node and Bun refuse an oversized message before buffering it; Bun before 1.4 does so by dropping the connection, so its peer sees `1006` rather than `1009` (Bun 1.4 and later send `1009`). Deno and workerd expose no such option, so there the message is received in full and then refused, and its memory is bounded by the platform's own cap. Worst-case buffered inbound memory is about `maxConnections × maxWsQueue × maxWsMessageBytes`, ≈ 15.6 GiB at the Node defaults; Deno and Bun have no connection cap, so set one at the platform or proxy there.
chrnx closed this issue 2026-11-18 01:04:01 +00:00
Sign in to join this conversation.