Skip to content

Commit 6624f80

Browse files
sam-githubtargos
authored andcommitted
tls: fix createSecureContext() cipher list filter
PR-URL: #27614 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent b8b02c3 commit 6624f80

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/_tls_common.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ exports.createSecureContext = function createSecureContext(options) {
163163
// cipher suites all have a standard name format beginning with TLS_, so split
164164
// the ciphers and pass them to the appropriate API.
165165
const ciphers = (options.ciphers || tls.DEFAULT_CIPHERS).split(':');
166-
const cipherList = ciphers.filter((_) => !_.match(/^TLS_/)).join(':');
166+
const cipherList = ciphers.filter((_) => !_.match(/^TLS_/) &&
167+
_.length > 0).join(':');
167168
const cipherSuites = ciphers.filter((_) => _.match(/^TLS_/)).join(':');
168169

169170
if (cipherSuites === '' && cipherList === '') {

test/parallel/test-tls-set-ciphers.js

+10
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ test('TLS_AES_128_CCM_8_SHA256', U,
9191

9292
test('TLS_AES_128_CCM_8_SHA256', 'TLS_AES_128_CCM_8_SHA256',
9393
'TLS_AES_128_CCM_8_SHA256');
94+
95+
// Invalid cipher values
96+
test(9, 'AES256-SHA', U, 'ERR_INVALID_ARG_TYPE', U);
97+
test('AES256-SHA', 9, U, U, 'ERR_INVALID_ARG_TYPE');
98+
test(':', 'AES256-SHA', U, 'ERR_INVALID_OPT_VALUE', U);
99+
test('AES256-SHA', ':', U, U, 'ERR_INVALID_OPT_VALUE');
100+
101+
// Using '' is synonymous for "use default ciphers"
102+
test('TLS_AES_256_GCM_SHA384', '', 'TLS_AES_256_GCM_SHA384');
103+
test('', 'TLS_AES_256_GCM_SHA384', 'TLS_AES_256_GCM_SHA384');

0 commit comments

Comments
 (0)