doc: document invalid X509Certificate validity times

When a certificate's notBefore or notAfter time cannot be parsed,
validFrom and validTo return the string 'Bad time value', and
validFromDate and validToDate return an invalid Date. Relational
comparisons with an invalid Date are always false, so a naive expiry
check can treat such a certificate as valid. Document the current
behavior and tell callers to reject invalid dates first.

Signed-off-by: Sarthak Ahuja <39986642+SarthakAhuja@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/67406
Refs: https://github.com/nodejs/node/issues/67285
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
This commit is contained in:
Sarthak Ahuja authored and Antoine du Hamel committed 2026-11-16 10:09:56 +01:00
1 parent 67d57cfef1
commit 136ae6f518
1 file changed
+26
+26
View File
@@ -3517,6 +3517,9 @@ added: v15.6.0
The date/time from which this certificate is valid.
If the certificate's `notBefore` time cannot be parsed, this is the string
`'Bad time value'`.
### `x509.validFromDate`
<!-- YAML
@@ -3529,6 +3532,16 @@ added:
The date/time from which this certificate is valid, encapsulated in a `Date` object.
If the certificate's `notBefore` time cannot be parsed, this property is an
invalid `Date` whose `getTime()` method returns `NaN`.
Relational comparisons with an invalid `Date` evaluate to `false`. To check
whether the current time is within the certificate's validity period, use
`now >= x509.validFromDate && now <= x509.validToDate`. This expression
evaluates to `false` if either date is invalid. Checking
`now < x509.validFromDate || now > x509.validToDate` instead can fail to
reject certificates with invalid dates.
### `x509.validTo`
<!-- YAML
@@ -3539,6 +3552,9 @@ added: v15.6.0
The date/time until which this certificate is valid.
If the certificate's `notAfter` time cannot be parsed, this is the string
`'Bad time value'`.
### `x509.validToDate`
<!-- YAML
@@ -3551,6 +3567,16 @@ added:
The date/time until which this certificate is valid, encapsulated in a `Date` object.
If the certificate's `notAfter` time cannot be parsed, this property is an
invalid `Date` whose `getTime()` method returns `NaN`.
Relational comparisons with an invalid `Date` evaluate to `false`. To check
whether the current time is within the certificate's validity period, use
`now >= x509.validFromDate && now <= x509.validToDate`. This expression
evaluates to `false` if either date is invalid. Checking
`now < x509.validFromDate || now > x509.validToDate` instead can fail to
reject certificates with invalid dates.
### `x509.signature`
<!-- YAML