Skip to content

Commit 9e02b81

Browse files
committed
tls: use RegExp.escape to better escape servername
1 parent 00a8377 commit 9e02b81

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lib/internal/tls/wrap.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
ObjectSetPrototypeOf,
2828
ReflectApply,
2929
RegExp,
30+
RegExpEscape,
3031
Symbol,
3132
SymbolFor,
3233
} = primordials;
@@ -1541,11 +1542,7 @@ Server.prototype.addContext = function(servername, context) {
15411542
throw new ERR_TLS_REQUIRED_SERVER_NAME();
15421543
}
15431544

1544-
const re = new RegExp(`^${
1545-
servername
1546-
.replace(/([.^$+?\-\\[\]{}])/g, '\\$1')
1547-
.replaceAll('*', '[^.]*')
1548-
}$`);
1545+
const re = new RegExp(`^${RegExpEscape(servername).replace(/(?<=[^\\]|^)\\\*/g, '[^.]+')}$`);
15491546

15501547
const secureContext =
15511548
context instanceof common.SecureContext ? context : tls.createSecureContext(context);

0 commit comments

Comments
 (0)