Repository navigation
fix(http): keep WebSocket control frames out of fragmented messages - #904
Merged
Merged
Conversation
A control frame between the fragments of a data message overwrote the parser's opcode and was appended to the partial message, so the data message was echoed back inside PONG frames and never delivered. Buffer control frames separately so they no longer touch the data message state, and reject fragmented or oversized (>125 bytes) control frames as required by RFC 6455 5.5. Fixes #893
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation addresses the reported parser corruption and includes focused coverage for valid and invalid control frames.
0 open findings
What changed in this PR
Separates WebSocket control frames from fragmented data messages and enforces RFC 6455 control-frame limits.
Changes:
- Uses a dedicated control-frame buffer.
- Rejects fragmented or oversized control frames.
- Adds and registers parser tests.
| File | Description |
|---|---|
http/WebSocketParser.cpp |
Implements isolated control-frame parsing and validation. |
http/WebSocketParser.h |
Adds the control-frame buffer. |
unittest/websocket_parser_test.cpp |
Tests interleaving and invalid control frames. |
unittest/CMakeLists.txt |
Registers the CMake test target. |
Makefile |
Builds the test with HTTP enabled. |
scripts/unittest.sh |
Runs the test when available. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
onmessage, and its contents were echoed back inside PONG frames. RFC 6455 §5.4 allows control frames in the middle of a fragmented message, so conforming peers can trigger this.control_messagebuffer and are delivered when the frame ends, without touching the data message'sopcode,messageorstate.on_frame_headerreturns -1, soFeedRecvDatareturns a short count, and bothHttpServerandWebSocketClientalready close the connection in that case.websocket_parser_test, wired into the Makefile, CMake andscripts/unittest.sh.Scope
A CONTINUATION frame with no open message, and a new TEXT/BINARY frame while a fragmented message is open, behave as before. Other frame-header validation (masking direction, RSV bits, reserved opcodes) is not part of this change.
Verification
websocket_parser_testfails onmasterat the PING-between-fragments case and passes with this change./configure && make libhv unittest && make run-unitteston macOSwebsocket_parser_testbuilt with UBSan and run under Guard Malloc (libgmalloc)WebSocketServerend to end with raw framesTEXT(FIN=0) "Hel"+PING "x"+CONT(FIN=1) "lo": replies PONG"x"andonmessagereceives"Hello"(before: PONG"Helx"+ PONG"lo", noonmessage); a fragmented PING now closes the connectionWebSocketClientend to end against a server sending the same frames:onmessagereceives"Hello"and the client replies PONG"x"git diff --checkFixes #893