Skip to content

fix: reject non-finite DID token iat/ext/nbf - #156

Open
SashaMIT wants to merge 1 commit into
magiclabs:masterfrom
SashaMIT:bug/#155/didt-unparseable-timestamps
Open

fix: reject non-finite DID token iat/ext/nbf#156
SashaMIT wants to merge 1 commit into
magiclabs:masterfrom
SashaMIT:bug/#155/didt-unparseable-timestamps

Conversation

@SashaMIT

Copy link
Copy Markdown

Pull Request

token.validate() compared ext and nbf as numbers, but isDIDTClaim only required those fields to be non-null. A string such as ext: "never" makes ext < now false, so a correctly signed DID token never expires. The same happens for nbf ("later" - 300 is NaN).

This PR requires iat, ext, and nbf to be finite numbers. parseDIDToken then fail-closes as malformed, which is the path validate() 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/nbf turns that guard into a no-op. Same class as wevm/viem#4990 and thirdweb-dev/js#8875.

Fixed Issues

Fixes #155

Test instructions

yarn test

New coverage:

  • isDIDTClaim rejects string / NaN timestamps
  • parseDIDToken rejects ext: "never"
  • token.validate rejects a locally signed token whose ext is "never"

Revert-tested: dropping the isFiniteNumber check makes those six assertions fail (validate no longer throws).

Existing fixtures (VALID_DIDT, expired, future nbf) 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

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
@SashaMIT
SashaMIT requested a review from a team as a code owner August 14, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DID token validate fail-opens on non-numeric ext/nbf/iat

1 participant