fix(verify): validate clockTolerance is a non-negative number#1036
Open
abhu85 wants to merge 1 commit into
Open
fix(verify): validate clockTolerance is a non-negative number#1036abhu85 wants to merge 1 commit into
abhu85 wants to merge 1 commit into
Conversation
A non-number, NaN, Infinity, or negative `clockTolerance` silently corrupted the exp/nbf expiry checks. For example `clockTolerance: Infinity` makes `clockTimestamp >= exp + clockTolerance` always false, so an expired token is accepted with no error. Reject invalid values up front, mirroring the existing `clockTimestamp` validation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
verify()performs no validation on theclockToleranceoption, yet it is added directly to the timestamp comparisons:When
clockToleranceis an invalid value, this silently corrupts theexp/nbfchecks instead of erroring:Infinity→exp + Infinity === Infinity, soclockTimestamp >= Infinityis alwaysfalse→ an expired token is accepted with no error.NaN→ every comparison isfalse→ same silent bypass."5") →exp + "5"becomes string concatenation, producing nonsensical comparisons.This was reported in #1021.
Fix
Validate
clockToleranceup front and reject invalid values, mirroring the existingclockTimestamp must be a numberguard a few lines above:Scope / non-goals
The original report also suggested capping
clockToleranceat a fixed maximum (e.g. 300s). I deliberately did not add an upper bound: a large-but-finite tolerance is an unusual-but-legitimate configuration, and a hard cap would be a breaking change for anyone relying on it. This PR only rejects values that are unambiguously invalid (non-number /NaN/Infinity/ negative) and cause silent, surprising behavior. If the maintainers want a maximum, that is a separate policy decision and easy to layer on top.Test plan
option: clockTolerancetests intest/verify.tests.js(rejects string / negative / non-finite; confirms an expired token is rejected rather than silently accepted withInfinity; confirms a valid small tolerance still verifies).master(4/5) and pass with the fix.npm test(full suite + lint) passes: 516 passing, 1 pending, no regressions.Fixes #1021