Skip to content

inspector: fix out-of-bounds read in ws frame decoding#64618

Open
Nashit-h wants to merge 1 commit into
nodejs:mainfrom
Nashit-h:ws-frame-bounds-check
Open

inspector: fix out-of-bounds read in ws frame decoding#64618
Nashit-h wants to merge 1 commit into
nodejs:mainfrom
Nashit-h:ws-frame-bounds-check

Conversation

@Nashit-h

Copy link
Copy Markdown

decode_frame_hybi17 checks the announced payload length against buffer.size(), but the payload is read from it + kMaskingKeyWidthInBytes, after the iterator has already walked past the two byte header and the extended length field. A client that sends only the two header bytes of a masked frame, 0x81 0xFD, underflows buffer.size() - kMaskingKeyWidthInBytes to SIZE_MAX, passes the check, and the unmasking loop reads 125 bytes past a two byte vector; the bytes it picks up go to OnWsFrame and back out to the peer. Measuring against what is left after the header fixes both that underflow and the header bytes the old check never accounted for.

Signed-off-by: nashit hayyat <nashit@bugqore.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/inspector

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run. labels Jul 20, 2026
reinterpret_cast<uv_handle_t*>(&client_socket)));
}

TEST_F(InspectorSocketTest, WaitsForFrameBodyToArrive) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test also passed on the main branch without the patch.

Comment thread src/inspector_socket.cc
Comment on lines +366 to +367
if (remaining < kMaskingKeyWidthInBytes ||
remaining - kMaskingKeyWidthInBytes < payload_length)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads to me equivalent to this one liner:

Suggested change
if (remaining < kMaskingKeyWidthInBytes ||
remaining - kMaskingKeyWidthInBytes < payload_length)
if (remaining < kMaskingKeyWidthInBytes + payload_length)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants