Repository navigation
Conversation
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.
The author should do the following, if applicable
pnpm run check:fixto format and lint the codeProblem
Per RFC 7517 §4.2 (
use) and §4.3 (key_ops), JWKs can specify their intended public key usage:use:"sig"(signature verification) or"enc"(encryption).key_ops: an array of key operation values (e.g.["verify"],["encrypt"]).In
verifyWithJwks(), candidate key selection previously only filtered bykey.kid === header.kid:When a JWKS contains both an encryption key and a signature key sharing the same
kid(standard in dual-use certificates and enterprise identity providers such as Okta, Azure AD, and Cognito), or when a key with the requestedkidhasuse: "enc"or lacks"verify"inkey_ops,verifyKeys.find()would select the encryption key. Subsequently,crypto.subtle.importKey("jwk", key, alg, false, ["verify"])throws an uncaughtDOMException: DataError(Invalid JWK "use" ParameterorKey operations and usage mismatch) rather than selecting the valid signing key or throwingJwtTokenInvalid(token).Solution
Filter candidate keys in
verifyWithJwks()to only select keys compatible with asymmetric signature verification per RFC 7517:key.use === undefined || key.use === 'sig'key.key_ops === undefined || (Array.isArray(key.key_ops) && key.key_ops.includes('verify'))kid,verifyWithJwks()cleanly rejects withJwtTokenInvalid(token)instead of throwing an unhandledDataErrorDOMException.useorkey_opsremain accepted, maintaining full backwards compatibility.Tests
Added test cases to
src/utils/jwt/jwt.test.tsunderverifyWithJwks key handling:use: "sig"key when both encryption and signature keys share the samekid.key_ops: ["verify"]key when both encryption and verification keys share the samekid.JwtTokenInvalidwhen matchingkidonly hasuse: "enc".JwtTokenInvalidwhen matchingkidonly haskey_ops: ["encrypt"].src/utils/jwt/jwt.test.tspass cleanly.