fix(sdk-node): cap wire-controlled frame lengths before allocation (PILOT-103)#3
Open
matthew-pilot wants to merge 1 commit into
Open
fix(sdk-node): cap wire-controlled frame lengths before allocation (PILOT-103)#3matthew-pilot wants to merge 1 commit into
matthew-pilot wants to merge 1 commit into
Conversation
…ILOT-103) SDK read data-exchange ACK payloads and event-stream topic/payload frames using wire-controlled lengths (readUInt32BE/readUInt16BE on remote bytes) without any size cap. A malicious peer could advertise a 4 GiB length and force the SDK to attempt a single huge allocation, causing memory exhaustion and OOM kill on the host process. Add MAX_PAYLOAD_SIZE (1 MiB) and MAX_TOPIC_SIZE (4 KiB) guards: - sendMessage / sendFile: if ackLen > 1 MiB, skip ack and return - readEventFrame: if topicLen > 4 KiB or payloadLen > 1 MiB, return null (treated identically to an incomplete read — benign) All 173 existing tests pass; 1 new cap export test added. Closes PILOT-103
Collaborator
Author
|
📊 PR Status Report
Awaiting operator review. Canary can be triggered on request with |
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.
What failed
src/client.tsreads data-exchange ACK payloads (conn.read(ackLen)) and event-stream topic/payload frames (conn.read(topicLen),conn.read(payloadLen)) using wire-controlled lengths parsed from remote bytes without any size cap. A malicious or buggy peer can advertise a 4 GiB length and force the SDK to attempt a single huge allocation → memory exhaustion / OOM kill DoS on the host process.What was changed
Added
MAX_PAYLOAD_SIZE = 1_048_576(1 MiB) and exportedMAX_TOPIC_SIZE = 4_096(4 KiB) constants. Before eachconn.read(N)where N comes from the wire:ackLen > 1 MiB, skip the ACK read and return the basic result (same as a failed/incomplete ACK read today — already handled by the caller)topicLen > 4 KiBorpayloadLen > 1 MiB, returnnull(treated identically to an incomplete read — benign)Verification
tscbuild: ✅Closes PILOT-103