Skip to content

fix(network): prevent unhandled TypeError crash on invalid TCP payload type#5869

Open
Pranshmish wants to merge 1 commit into
node-red:mainfrom
Pranshmish:fix/tcp-unhandled-write-error
Open

fix(network): prevent unhandled TypeError crash on invalid TCP payload type#5869
Pranshmish wants to merge 1 commit into
node-red:mainfrom
Pranshmish:fix/tcp-unhandled-write-error

Conversation

@Pranshmish

Copy link
Copy Markdown

Summary

This PR fixes a Denial of Service (DoS) crash in the TCP Request / TCP Out nodes that occurs when a message's payload is mutated to an unsupported type (such as a number or object) after it has been enqueued but before it is written to the socket.

Node.js's internal socket.write() throws a synchronous TypeError when 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

  • Strict Validation in 31-tcpin.js: Added validation to verify that event.msg.payload is either a string, a Buffer, or a Uint8Array before invoking .write(). If invalid, node.error() is called to log the issue safely.
  • Robust Exception Handling: Wrapped the .write() call in a try/catch block to protect against any unexpected socket-level write exceptions.
  • Leak Prevention: Kept the vital event.nodeDone() call intact to ensure Node-RED's message tracking lifecycle completes correctly under both valid and invalid payload branches.
  • Regression Unit Test in 31-tcprequest_spec.js: Added a test case that replicates the asynchronous mutation of payload to 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.js
Result: All 17 tests passed successfully.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 13, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Pranshmish / name: Pranshmish (db4c286)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant