From e68118ecbc55354e0d6306d83174417480765758 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 15 Dec 2023 00:50:33 +0100 Subject: [PATCH] Improve on new SNI-related changes --- svr.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/svr.js b/svr.js index 023d163..d80f559 100644 --- a/svr.js +++ b/svr.js @@ -1292,7 +1292,7 @@ if (secure) { var sniNames = Object.keys(sni); var sniCredentials = []; sniNames.forEach(function (sniName) { - if(typeof sniName === "string" && sniName.match(/\*[^*.]*\*[^*.]*(?:\.|$)/)) { + if(typeof sniName === "string" && sniName.match(/\*[^*.:]*\*[^*.:]*(?:\.|:|$)/)) { sniReDos = true; } sniCredentials.push({ @@ -2116,7 +2116,8 @@ if (!cluster.isPrimary) { key: sniCredentialsSingle.key }); try { - server._contexts[server._contexts.length-1][0] = new RegExp("^" + sniCredentialsSingle.name.replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "\.?$", "i"); + var snMatches = sniCredentialsSingle.name.match(/^([^:[]*|\[[^]]*\]?)((?::.*)?)$/); + server._contexts[server._contexts.length-1][0] = new RegExp("^" + snMatches[1].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.:]*") + ((snMatches[1][0] == "[" || snMatches[1].match(/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/)) ? "" : "\.?") + snMatches[2].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "$", "i"); } catch(ex) {} }); }