From b11b4cc69dcaa7da4a99cde5a1b1f1abe909f731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 7 Dec 2021 02:14:49 +0000 Subject: [PATCH] tls: drop support for URI alternative names Previously, Node.js incorrectly accepted uniformResourceIdentifier (URI) subject alternative names in checkServerIdentity regardless of the application protocol. This was incorrect even in the most common cases. For example, RFC 2818 specifies (and RFC 6125 confirms) that HTTP over TLS only uses dNSName and iPAddress subject alternative names, but not uniformResourceIdentifier subject alternative names. Additionally, name constrained certificate authorities might not be constrained to specific URIs, allowing them to issue certificates for URIs that specify hosts that they would not be allowed to issue dNSName certificates for. Even for application protocols that make use of URI subject alternative names (such as SIP, see RFC 5922), Node.js did not implement the required checks correctly, for example, because checkServerIdentity ignores the URI scheme. As a side effect, this also fixes an edge case. When a hostname is not an IP address and no dNSName subject alternative name exists, the subject's Common Name should be considered even when an iPAddress subject alternative name exists. It remains possible for users to pass a custom checkServerIdentity function to the TLS implementation in order to implement custom identity verification logic. This addresses CVE-2021-44531. Co-authored-by: Akshay K CVE-ID: CVE-2021-44531 Backport-PR-URL: https://github.com/nodejs-private/node-private/pull/303 PR-URL: https://github.com/nodejs-private/node-private/pull/300 Reviewed-By: Michael Dawson Reviewed-By: Rich Trott --- doc/api/tls.md | 12 +++++++ lib/tls.js | 21 +++---------- test/fixtures/keys/Makefile | 14 +++++++++ .../irrelevant_san_correct_subject-cert.pem | 11 +++++++ .../irrelevant_san_correct_subject-key.pem | 5 +++ .../test-tls-check-server-identity.js | 14 ++++----- test/parallel/test-x509-escaping.js | 31 ++++++++++++++++--- 7 files changed, 80 insertions(+), 28 deletions(-) create mode 100644 test/fixtures/keys/irrelevant_san_correct_subject-cert.pem create mode 100644 test/fixtures/keys/irrelevant_san_correct_subject-key.pem diff --git a/doc/api/tls.md b/doc/api/tls.md index c45c778da76ac5..cdd678c56e869a 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1460,6 +1460,11 @@ decrease overall server throughput. * `hostname` {string} The host name or IP address to verify the certificate @@ -1480,6 +1485,12 @@ the checks done with additional verification. This function is only called if the certificate passed all other checks, such as being issued by trusted CA (`options.ca`). +Earlier versions of Node.js incorrectly accepted certificates for a given +`hostname` if a matching `uniformResourceIdentifier` subject alternative name +was present (see [CVE-2021-44531][]). Applications that wish to accept +`uniformResourceIdentifier` subject alternative names can use a custom +`options.checkServerIdentity` function that implements the desired behavior. + ## `tls.connect(options[, callback])`