fix: reject non-finite DID token iat/ext/nbf - #156
Open
SashaMIT wants to merge 1 commit into
Open
Conversation
isDIDTClaim only required those fields to be non-null. A string ext (for example "never") makes ext < now evaluate to false, so validate() accepts a signed token that never expires. Same for nbf. Require finite numbers so parseDIDToken fail-closes as malformed. Fixes magiclabs#155
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.
Pull Request
token.validate()comparedextandnbfas numbers, butisDIDTClaimonly required those fields to be non-null. A string such asext: "never"makesext < nowfalse, so a correctly signed DID token never expires. The same happens fornbf("later" - 300isNaN).This PR requires
iat,ext, andnbfto be finite numbers.parseDIDTokenthen fail-closes as malformed, which is the pathvalidate()already uses.Threat model: the signer already controls a key that can produce a DID token for that issuer. The server-side lifetime check is the remaining guard. Unparseable
ext/nbfturns that guard into a no-op. Same class as wevm/viem#4990 and thirdweb-dev/js#8875.Fixed Issues
Fixes #155
Test instructions
yarn testNew coverage:
isDIDTClaimrejects string / NaN timestampsparseDIDTokenrejectsext: "never"token.validaterejects a locally signed token whoseextis"never"Revert-tested: dropping the
isFiniteNumbercheck makes those six assertions fail (validate no longer throws).Existing fixtures (
VALID_DIDT, expired, futurenbf) still pass. Full suite: 92/92.Don't forget to add a semver label!
patch(bug fix, no API change for well-formed tokens)Made with Cursor