From e79e67f6dc3c845cc100afadeb4cbdda46c7c795 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Tue, 11 Mar 2025 23:48:27 +0900 Subject: [PATCH] net: validate non-string host for socket.connect Signed-off-by: Daeyeon Jeong PR-URL: https://github.com/nodejs/node/pull/57198 Reviewed-By: James M Snell --- 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 165161094f8..f1cda502e5f 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 05a56546309..3c748b15161 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', + }); +}