Skip to content

Commit e6ba945

Browse files
committed
crypto: change default check(Host|Email) behavior
This changes the default behavior of the X509Certificate functions checkHost and checkEmail to match the default behavior of OpenSSL's X509_check_host and X509_check_email functions, respectively, which is also what RFC 2818 mandates for HTTPS. Refs: #36804 Refs: #41569
1 parent eda54ba commit e6ba945

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

doc/api/crypto.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,9 @@ added: v15.6.0
24722472
<!-- YAML
24732473
added: v15.6.0
24742474
changes:
2475+
- version: REPLACEME
2476+
pr-url: https://github.com/nodejs/node/pull/41600
2477+
description: The subject option now defaults to `'default'`.
24752478
- version: REPLACEME
24762479
pr-url: https://github.com/nodejs/node/pull/41569
24772480
description: The subject option can now be set to `'default'`.
@@ -2480,7 +2483,7 @@ changes:
24802483
* `email` {string}
24812484
* `options` {Object}
24822485
* `subject` {string} `'default'`, `'always'`, or `'never'`.
2483-
**Default:** `'always'`.
2486+
**Default:** `'default'`.
24842487
* `wildcards` {boolean} **Default:** `true`.
24852488
* `partialWildcards` {boolean} **Default:** `true`.
24862489
* `multiLabelWildcards` {boolean} **Default:** `false`.
@@ -2490,14 +2493,14 @@ changes:
24902493

24912494
Checks whether the certificate matches the given email address.
24922495

2496+
If the `'subject'` option is undefined or set to `'default`', the certificate
2497+
subject is only considered if the subject alternative name extension either does
2498+
not exist or does not contain any email addresses.
2499+
24932500
If the `'subject'` option is set to `'always'` and if the subject alternative
24942501
name extension either does not exist or does not contain a matching email
24952502
address, the certificate subject is considered.
24962503

2497-
If the `'subject'` option is set to `'default`', the certificate subject is only
2498-
considered if the subject alternative name extension either does not exist or
2499-
does not contain any email addresses.
2500-
25012504
If the `'subject'` option is set to `'never'`, the certificate subject is never
25022505
considered, even if the certificate contains no subject alternative names.
25032506

@@ -2506,6 +2509,9 @@ considered, even if the certificate contains no subject alternative names.
25062509
<!-- YAML
25072510
added: v15.6.0
25082511
changes:
2512+
- version: REPLACEME
2513+
pr-url: https://github.com/nodejs/node/pull/41600
2514+
description: The subject option now defaults to `'default'`.
25092515
- version: REPLACEME
25102516
pr-url: https://github.com/nodejs/node/pull/41569
25112517
description: The subject option can now be set to `'default'`.
@@ -2514,7 +2520,7 @@ changes:
25142520
* `name` {string}
25152521
* `options` {Object}
25162522
* `subject` {string} `'default'`, `'always'`, or `'never'`.
2517-
**Default:** `'always'`.
2523+
**Default:** `'default'`.
25182524
* `wildcards` {boolean} **Default:** `true`.
25192525
* `partialWildcards` {boolean} **Default:** `true`.
25202526
* `multiLabelWildcards` {boolean} **Default:** `false`.
@@ -2530,15 +2536,15 @@ or it might contain wildcards (e.g., `*.example.com`). Because host name
25302536
comparisons are case-insensitive, the returned subject name might also differ
25312537
from the given `name` in capitalization.
25322538

2539+
If the `'subject'` option is undefined or set to `'default'`, the certificate
2540+
subject is only considered if the subject alternative name extension either does
2541+
not exist or does not contain any DNS names. This behavior is consistent with
2542+
[RFC 2818][] ("HTTP Over TLS").
2543+
25332544
If the `'subject'` option is set to `'always'` and if the subject alternative
25342545
name extension either does not exist or does not contain a matching DNS name,
25352546
the certificate subject is considered.
25362547

2537-
If the `'subject'` option is set to `'default'`, the certificate subject is only
2538-
considered if the subject alternative name extension either does not exist or
2539-
does not contain any DNS names. This behavior is consistent with [RFC 2818][]
2540-
("HTTP Over TLS").
2541-
25422548
If the `'subject'` option is set to `'never'`, the certificate subject is never
25432549
considered, even if the certificate contains no subject alternative names.
25442550

lib/internal/crypto/x509.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function isX509Certificate(value) {
6565
function getFlags(options = {}) {
6666
validateObject(options, 'options');
6767
const {
68-
// TODO(tniessen): change the default to 'default'
69-
subject = 'always', // Can be 'default', 'always', or 'never'
68+
subject = 'default', // Can be 'default', 'always', or 'never'
7069
wildcards = true,
7170
partialWildcards = true,
7271
multiLabelWildcards = false,

test/parallel/test-x509-escaping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ const { hasOpenSSL3 } = common;
425425
assert.strictEqual(certX509.subjectAltName, 'DNS:evil.example.com');
426426

427427
// The newer X509Certificate API allows customizing this behavior:
428-
assert.strictEqual(certX509.checkHost(servername), servername);
428+
assert.strictEqual(certX509.checkHost(servername), undefined);
429429
assert.strictEqual(certX509.checkHost(servername, { subject: 'default' }),
430430
undefined);
431431
assert.strictEqual(certX509.checkHost(servername, { subject: 'always' }),

0 commit comments

Comments
 (0)