fix: unbounded WebSocket message reads allow memory exhaustion - #16
Open
I3eg1nner wants to merge 3 commits into
Open
fix: unbounded WebSocket message reads allow memory exhaustion#16I3eg1nner wants to merge 3 commits into
I3eg1nner wants to merge 3 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebSocket message handling has no size limit in either backend:
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