Skip to content

Commit 092fb9f

Browse files
authored
tls: use validateFunction for options.checkServerIdentity
If user uses invalid type for `options.checkServerIdentity` in tls.connect(), it's not internal issue of Node.js. So validateFunction() is more proper than assert(). Fixes: #49839 PR-URL: #49896 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent e6e320e commit 092fb9f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/_tls_wrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ exports.connect = function connect(...args) {
17381738
if (!options.keepAlive)
17391739
options.singleUse = true;
17401740

1741-
assert(typeof options.checkServerIdentity === 'function');
1741+
validateFunction(options.checkServerIdentity, 'options.checkServerIdentity');
17421742
assert(typeof options.minDHSize === 'number',
17431743
'options.minDHSize is not a number: ' + options.minDHSize);
17441744
assert(options.minDHSize > 0,

test/parallel/test-tls-basic-validations.js

+9
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,12 @@ assert.throws(() => { tls.createSecureContext({ maxVersion: 'fhqwhgads' }); },
135135
code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
136136
name: 'TypeError'
137137
});
138+
139+
for (const checkServerIdentity of [undefined, null, 1, true]) {
140+
assert.throws(() => {
141+
tls.connect({ checkServerIdentity });
142+
}, {
143+
code: 'ERR_INVALID_ARG_TYPE',
144+
name: 'TypeError',
145+
});
146+
}

0 commit comments

Comments
 (0)