Fix/regex non deterministic validation#593
Merged
antoatta85 merged 5 commits intomasterfrom Apr 9, 2026
Merged
Conversation
…terministic allowed-claim validation
… (will be done in another pr)
|
@antoatta85 Could you fix this build? |
SociableSteve
approved these changes
Apr 8, 2026
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.
fix: reset RegExp
lastIndexbefore claim validation to prevent non-deterministic verificationVulnerability
RegExp.prototype.test()is stateful when the/gor/yflags are set — each call mutateslastIndexon the same object.ensureStringClaimMatcher()insrc/verifier.jsreturned RegExp objects directly, andvalidateClaimValues()called.test()on them repeatedly without resettinglastIndex. This caused every second verification call to fail for perfectly valid tokens, producing an alternating PASS/FAIL pattern across allallowed*claim options (allowedAud,allowedIss,allowedSub,allowedJti,allowedNonce).The result is a logical denial-of-service: ~50% of valid authentication requests are rejected when any
allowed*option uses a RegExp with/gor/y.Fix
In
ensureStringClaimMatcher()(src/verifier.js), RegExp instances are now wrapped in a closure that resetslastIndex = 0before each.test()call:Custom matcher objects (anything else with a
.testmethod) and string-based matchers are unaffected.Tests added (
test/verifier.spec.js)stateful RegExp /g flag must not cause non-deterministic claim validation - allowedAudstateful RegExp /y flag must not cause non-deterministic claim validation - allowedAudstateful RegExp /g flag must not cause non-deterministic claim validation - allowedIssstateful RegExp /g flag must not cause non-deterministic claim validation - allowedSubstateful RegExp /g flag must not cause non-deterministic claim validation - allowedJtistateful RegExp /g flag must not cause non-deterministic claim validation - allowedNonceEach test verifies that 8 consecutive calls with the same valid token all succeed when a stateful RegExp is used in the corresponding
allowed*option.FIXES #592