diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index c5f30c01fa18e7..5961fbf0f7c782 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -1412,6 +1412,7 @@ Server.prototype.addContext = function(servername, context) { if (!servername) { throw new ERR_TLS_REQUIRED_SERVER_NAME(); } +servername = servername.toLowerCase() const re = new RegExp('^' + servername.replace(/([.^$+?\-\\[\]{}])/g, '\\$1') @@ -1435,8 +1436,8 @@ Server.prototype[EE.captureRejectionSymbol] = function( function SNICallback(servername, callback) { const contexts = this.server._contexts; - - for (const elem of contexts) { + for (let i = contexts.length - 1; i >= 0 ; i--) { + const elem = contexts[i] if (elem[0].test(servername)) { callback(null, elem[1]); return;