Skip to content

fix: unbounded WebSocket message reads allow memory exhaustion - #16

Open
I3eg1nner wants to merge 3 commits into
oboard:mainfrom
I3eg1nner:fix/cwe400-ws-message-limit
Open

fix: unbounded WebSocket message reads allow memory exhaustion#16
I3eg1nner wants to merge 3 commits into
oboard:mainfrom
I3eg1nner:fix/cwe400-ws-message-limit

Conversation

@I3eg1nner

Copy link
Copy Markdown
Contributor

WebSocket message handling has no size limit in either backend:

  • native: msg.read_all() buffers the entire message into memory
  • mongoose: Array::make(ws_msg_body_len(), ...) trusts the frame
    header's declared length, allocating arbitrarily large buffers

A single malicious client can OOM the server.

Fix: reuse the existing read_body_limited() for native WS reads.
For mongoose, reject frames exceeding max_body_size before allocation.

🤖 Generated with Claude Code

I3eg1nner and others added 2 commits August 18, 2026 15:38
Both the native and mongoose backends read WS messages without a size
limit. A malicious client can exhaust server memory:
- native: msg.read_all() buffers the entire message
- mongoose: Array::make(ws_msg_body_len(), ...) allocates based on the
  frame header's declared length, which can be arbitrarily large

Reuse the existing read_body_limited() for native text/binary messages.
For mongoose, reject frames whose declared size exceeds max_body_size
before allocating.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…runcated prefix

1. Mongoose __ws_emit "message" branch had no size check — text
   messages of any size reached the handler. Add the same
   ws_max_body_size guard as the binary branch.

2. Native read_body_limited returns a truncated prefix when a message
   exceeds max_body_size (e.g. 8192 bytes of a 10000-byte message).
   Add read_ws_limited that returns None on overflow; the WS handler
   now silently drops oversized messages instead of dispatching
   partial data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ces max_body_size

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant