From 7a7ae44d643b153465f14e707d92ec4d72482888 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Mon, 24 Feb 2025 20:50:28 +0900 Subject: [PATCH] net: validate non-string host for socket.connect Signed-off-by: Daeyeon Jeong --- lib/net.js | 2 ++ test/parallel/test-net-connect-options-invalid.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/net.js b/lib/net.js index b8c0057bfd1a6c..172cb783b3fbb7 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1311,6 +1311,8 @@ function lookupAndConnect(self, options) { const host = options.host || 'localhost'; let { port, autoSelectFamilyAttemptTimeout, autoSelectFamily } = options; + validateString(host, 'options.host'); + if (localAddress && !isIP(localAddress)) { throw new ERR_INVALID_IP_ADDRESS(localAddress); } diff --git a/test/parallel/test-net-connect-options-invalid.js b/test/parallel/test-net-connect-options-invalid.js index 05a565463099ec..3c748b151610b1 100644 --- a/test/parallel/test-net-connect-options-invalid.js +++ b/test/parallel/test-net-connect-options-invalid.js @@ -25,3 +25,15 @@ const net = require('net'); }); }); } + +{ + assert.throws(() => { + net.createConnection({ + host: ['192.168.0.1'], + port: 8080, + }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + }); +}