fix(websocket): validate inline payload with current opcode#5432
Open
mcollina wants to merge 1 commit into
Open
fix(websocket): validate inline payload with current opcode#5432mcollina wants to merge 1 commit into
mcollina wants to merge 1 commit into
Conversation
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Member
Author
|
cc @lpinca |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5432 +/- ##
=======================================
Coverage 93.36% 93.36%
=======================================
Files 110 110
Lines 36993 36993
=======================================
Hits 34537 34537
Misses 2456 2456 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
lpinca
reviewed
Jun 15, 2026
Comment on lines
+356
to
+361
| const socket = ws._socket | ||
|
|
||
| // Ping frame followed by a 2-byte text frame. The text frame must be | ||
| // validated as data, not as the previous control frame. | ||
| socket.write(Buffer.from([0x89, 0x01, 0x78])) | ||
| socket.write(Buffer.from([0x81, 0x02, 0x61, 0x62])) |
Member
There was a problem hiding this comment.
Suggested change
| const socket = ws._socket | |
| // Ping frame followed by a 2-byte text frame. The text frame must be | |
| // validated as data, not as the previous control frame. | |
| socket.write(Buffer.from([0x89, 0x01, 0x78])) | |
| socket.write(Buffer.from([0x81, 0x02, 0x61, 0x62])) | |
| // The text frame must be validated as data, not as the previous control frame. | |
| ws.ping() | |
| ws.send('ab') |
|
|
||
| const result = await Promise.race([ | ||
| once(client, 'close'), | ||
| sleep(5000, timeout) |
Member
There was a problem hiding this comment.
Isn't it cleaner to customize the default test timeout?
Comment on lines
+403
to
+408
| const socket = ws._socket | ||
|
|
||
| // 1-byte text frame at the limit followed by a 2-byte ping. The ping | ||
| // must be validated as a control frame, not as the previous data frame. | ||
| socket.write(Buffer.from([0x81, 0x01, 0x61])) | ||
| socket.write(Buffer.from([0x89, 0x02, 0x78, 0x79])) |
Member
There was a problem hiding this comment.
Suggested change
| const socket = ws._socket | |
| // 1-byte text frame at the limit followed by a 2-byte ping. The ping | |
| // must be validated as a control frame, not as the previous data frame. | |
| socket.write(Buffer.from([0x81, 0x01, 0x61])) | |
| socket.write(Buffer.from([0x89, 0x02, 0x78, 0x79])) | |
| // The ping must be validated as a control frame, not as the previous text frame. | |
| ws.send('a') | |
| ws.ping('xy') |
I guess this is by design, but why is the limit ignored for control frames? If I set it 50 bytes, I would expect it to also apply for control frames.
lpinca
approved these changes
Jun 15, 2026
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.
This relates to...
WebSocket
maxPayloadSizevalidation for inline (<=125byte) frames.Rationale
The inline payload-length path validated
maxPayloadSizebefore storing the current frame opcode in parser state. This allowed stale opcode decisions across control/data frame transitions: a preceding control frame could make oversized data bypass the limit, and a preceding data frame could cause legal control frames to be counted toward the limit.Changes
Features
N/A
Bug Fixes
Breaking Changes and Deprecations
N/A
Status
Validation:
node --test test/websocket/fragments.js test/websocket/permessage-deflate-limit.js test/websocket/permessage-deflate-config.js test/websocket/stream/too-many-fragments.jsnpm run lint