[fix] Fixing Default maxFragments still allows memory exhaustion Dos#2332
Open
codepawpaw wants to merge 1 commit into
Open
[fix] Fixing Default maxFragments still allows memory exhaustion Dos#2332codepawpaw wants to merge 1 commit into
codepawpaw wants to merge 1 commit into
Conversation
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.
Issue: #2331
Problem:
The GHSA-96hv-2xvq-fx4p fix added the count-based guards maxFragments and maxBufferedChunks, but their defaults are high enough that a default-configured server can still be OOM-crashed by a single unauthenticated peer.
Both guards count parts, and the only byte-based guard (maxPayload) counts payload bytes only. Nothing accounts for the per-Buffer-view object overhead (~128 B each). An attacker can exploit this:
Send a text frame with FIN=0, then maxFragments - 2 one-byte continuation frames, and never send FIN.
The message never completes, so the fragment array is retained indefinitely.
_totalPayloadLength stays ~128 KB (far below maxPayload of 100 MB) and the fragment count stays just under maxFragments (131072), so no guard ever fires.
Reproduced on the current tree (default server options): ~0.87 MB of wire traffic pins ~13–16 MB of heap (≈15× amplification). A few dozen such connections OOM-kill a default-heap Node process.
Fix
Two complementary changes:
New maxBufferedBytes option (structural fix). Charges a fixed per-part overhead (BUFFER_OVERHEAD = 128) on top of payload bytes, so the limit bounds the memory actually pinned rather than only the payload size. Enforced on all three retention paths — buffered input chunks (_write), uncompressed fragments (getData), and compressed fragments (decompress). Exceeding it emits WS_ERR_TOO_MANY_BUFFERED_PARTS (close code 1008).
Lowered the default count limits (defense-in-depth)
maxBufferedBytes defaults above maxPayload (100 MiB) so that a legitimate max-size message is never rejected; the tighter count defaults are what cap per-connection retained memory in the default configuration
New behavior is opt-in at the Receiver level (maxBufferedBytes defaults to 0 = disabled there). The lowered maxFragments/maxBufferedChunks defaults are a behavior change only for peers sending an unusually large number of fragments/chunks in a single message, all limits remain configurable (set to 0 to disable).