Skip to content

Commit df1b2c3

Browse files
tniessenkumarak
authored andcommittedJan 7, 2022
crypto,tls: implement safe x509 GeneralName format
This change introduces JSON-compatible escaping rules for strings that include X.509 GeneralName components (see RFC 5280). This non-standard format avoids ambiguities and prevents injection attacks that could previously lead to X.509 certificates being accepted even though they were not valid for the target hostname. These changes affect the format of subject alternative names and the format of authority information access. The checkServerIdentity function has been modified to safely handle the new format, eliminating the possibility of injecting subject alternative names into the verification logic. Because each subject alternative name is only encoded as a JSON string literal if necessary for security purposes, this change will only be visible in rare cases. This addresses CVE-2021-44532. Co-authored-by: Akshay K <iit.akshay@gmail.com> CVE-ID: CVE-2021-44532 Backport-PR-URL: nodejs-private/node-private#305 PR-URL: nodejs-private/node-private#300 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent b14be42 commit df1b2c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2428
-42
lines changed
 

‎doc/api/errors.md

+8
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,14 @@ An unspecified or non-specific system error has occurred within the Node.js
19751975
process. The error object will have an `err.info` object property with
19761976
additional details.
19771977

1978+
<a id="ERR_TLS_CERT_ALTNAME_FORMAT"></a>
1979+
### `ERR_TLS_CERT_ALTNAME_FORMAT`
1980+
1981+
This error is thrown by `checkServerIdentity` if a user-supplied
1982+
`subjectaltname` property violates encoding rules. Certificate objects produced
1983+
by Node.js itself always comply with encoding rules and will never cause
1984+
this error.
1985+
19781986
<a id="ERR_TLS_CERT_ALTNAME_INVALID"></a>
19791987
### `ERR_TLS_CERT_ALTNAME_INVALID`
19801988

‎lib/_tls_common.js

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
ArrayIsArray,
26+
JSONParse,
2627
ObjectCreate,
2728
} = primordials;
2829

@@ -323,6 +324,14 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) {
323324

324325
// XXX: More key validation?
325326
info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, (all, key, val) => {
327+
if (val.charCodeAt(0) === 0x22) {
328+
// The translatePeerCertificate function is only
329+
// used on internally created legacy certificate
330+
// objects, and any value that contains a quote
331+
// will always be a valid JSON string literal,
332+
// so this should never throw.
333+
val = JSONParse(val);
334+
}
326335
if (key in c.infoAccess)
327336
c.infoAccess[key].push(val);
328337
else

0 commit comments

Comments
 (0)
Please sign in to comment.