fix(network): prevent unhandled TypeError crash on invalid TCP payload type#5869
Open
Pranshmish wants to merge 1 commit into
Open
fix(network): prevent unhandled TypeError crash on invalid TCP payload type#5869Pranshmish wants to merge 1 commit into
Pranshmish 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.
Summary
This PR fixes a Denial of Service (DoS) crash in the TCP Request / TCP Out nodes that occurs when a message's
payloadis mutated to an unsupported type (such as anumberorobject) after it has been enqueued but before it is written to the socket.Node.js's internal
socket.write()throws a synchronousTypeErrorwhen it receives an invalid argument type. Because this write operation runs asynchronously inside the network connection callback or event emitter context, the exception goes uncaught, causing Node-RED to crash.Changes
31-tcpin.js: Added validation to verify thatevent.msg.payloadis either astring, aBuffer, or aUint8Arraybefore invoking.write(). If invalid,node.error()is called to log the issue safely..write()call in atry/catchblock to protect against any unexpected socket-level write exceptions.event.nodeDone()call intact to ensure Node-RED's message tracking lifecycle completes correctly under both valid and invalid payload branches.31-tcprequest_spec.js: Added a test case that replicates the asynchronous mutation ofpayloadto a number, confirming that it is safely rejected and logged as a node error without crashing Node-RED.Verification
Verified locally by running the Mocha test suite:
npx mocha test/nodes/core/network/31-tcprequest_spec.jsResult: All 17 tests passed successfully.