Skip to content

doc: document invalid X509Certificate validity times - #67406

Open
SarthakAhuja wants to merge 3 commits into
nodejs:mainfrom
SarthakAhuja:crypto-doc-bad-time-value
Open

SarthakAhuja wants to merge 3 commits into
nodejs:mainfrom
SarthakAhuja:crypto-doc-bad-time-value

Conversation

@SarthakAhuja

Copy link
Copy Markdown

Refs: #67285

panva asked on the issue for this to be documented, because it affects checking a certificate's expiry date: #67285 (comment)

I searched for "Bad time value" and found where it comes from in deps/ncrypto/ncrypto.cc. I also checked with node -e that comparing an invalid Date with Date.now() always gives false.

I used Claude to help write the documentation wording, run lint, and fix the English in this description.

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>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to Node.js documentation. labels Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@panva

panva commented Nov 11, 2026

Copy link
Copy Markdown
Member

I believe the most important part that's missing is advising to do a positive validity-window check (now >= notBefore && now <= notAfter) so that an invalid bound is rejected, while an out-of-range check (now < notBefore || now > notAfter) could fall victim to this quirk.

Per review, tell callers to test that the current time is inside the
validity window, which rejects an invalid bound, instead of testing
whether it is outside the window, which an invalid bound passes.

Signed-off-by: Sarthak Ahuja <39986642+SarthakAhuja@users.noreply.github.com>
@SarthakAhuja

Copy link
Copy Markdown
Author

Thanks panva, you're right. Just saying to reject an invalid date is not enough.

In both validFromDate and validToDate, I now recommend the positive window check, and I added a warning that the out-of-range check accepts an invalid date.

I checked with Node that both checks return false for an invalid bound, which means the out-of-range check lets the certificate pass.

Comment thread doc/api/crypto.md Resolved
Comment thread doc/api/crypto.md Resolved
Apply the review suggestions for validFromDate and validToDate.

Signed-off-by: Sarthak Ahuja <39986642+SarthakAhuja@users.noreply.github.com>
@panva panva added the commit-queue-squash PRs the Commit Queue should land as one squashed commit. label Nov 11, 2026
@panva
panva requested a review from pimterry November 11, 2026 10:05
@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to Node.js documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants