From e0fe6a635e5929a364986a6c39dc3585b9ddcd85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 29 Dec 2021 20:23:11 -0500 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/306 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 | 33 +++-------------- 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 | 28 ++++----------- test/parallel/test-x509-escaping.js | 36 ++++++++++++++++--- 7 files changed, 85 insertions(+), 54 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 c9fabbc5b59cf9..e2c4af9df29c2d 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1323,6 +1323,11 @@ decrease overall server throughput. ## `tls.checkServerIdentity(hostname, cert)` * `hostname` {string} The host name or IP address to verify the certificate @@ -1343,6 +1348,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])`