From ebda73470df57ffddd21eef962942e82277c8054 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 11 May 2026 13:02:28 +0200 Subject: [PATCH] tls: normalize hostname for server identity checks Signed-off-by: Matteo Collina PR-URL: https://github.com/nodejs-private/node-private/pull/869 Reviewed-By: Antoine du Hamel CVE-ID: CVE-2026-48618 Refs: https://hackerone.com/reports/3688064 --- lib/tls.js | 20 ++++++++++++------- .../test-tls-check-server-identity.js | 9 +++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index 4c5dece3be0..ffc38e23c85 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -68,6 +68,7 @@ const { Buffer } = require('buffer'); const { canonicalizeIP } = internalBinding('cares_wrap'); const tlsCommon = require('internal/tls/common'); const tlsWrap = require('internal/tls/wrap'); +const { domainToASCII } = require('internal/url'); const { validateString } = require('internal/validators'); const { @@ -403,6 +404,11 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { const ips = []; hostname = '' + hostname; + const hostnameASCII = domainToASCII(hostname); + + // Remove trailing dots for error messages and matching. + hostname = unfqdn(hostname); + const hostnameASCIIWithoutFQDN = unfqdn(hostnameASCII); if (altNames) { const splitAltNames = altNames.includes('"') ? @@ -420,14 +426,14 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { let valid = false; let reason = 'Unknown reason'; - hostname = unfqdn(hostname); // Remove trailing dot for error messages. - - if (net.isIP(hostname)) { - valid = ips.includes(canonicalizeIP(hostname)); - if (!valid) - reason = `IP: ${hostname} is not in the cert's list: ` + ips.join(', '); + if (net.isIP(hostnameASCIIWithoutFQDN)) { + valid = ips.includes(canonicalizeIP(hostnameASCIIWithoutFQDN)); + if (!valid) { + reason = + `IP: ${hostname} is not in the cert's list: ` + ips.join(', '); + } } else if (dnsNames.length > 0 || subject?.CN) { - const hostParts = splitHost(hostname); + const hostParts = splitHost(hostnameASCIIWithoutFQDN); const wildcard = (pattern) => check(hostParts, pattern, true); if (dnsNames.length > 0) { diff --git a/test/parallel/test-tls-check-server-identity.js b/test/parallel/test-tls-check-server-identity.js index 6918638230c..4863fca5516 100644 --- a/test/parallel/test-tls-check-server-identity.js +++ b/test/parallel/test-tls-check-server-identity.js @@ -381,6 +381,15 @@ const tests = [ error: 'Host: localhost. is not in the cert\'s altnames: ' + 'DNS:a.com' }, + { + host: 'foo。bar.example.com', + cert: { + subjectaltname: 'DNS:*.example.com', + subject: {} + }, + error: 'Host: foo。bar.example.com. is not in the cert\'s altnames: ' + + 'DNS:*.example.com' + }, // IDNA { host: 'xn--bcher-kva.example.com',