Repository navigation
Conversation
RFC 7515 says to reject a token whose crit header lists an extension the recipient doesn't understand. Which extensions an application understands is up to the application, so the check only runs when known_crit is given: JWT.decode(token, key, true, algorithm: 'HS256', known_crit: []) encoded_token.verify_claims!(:exp, known_crit: ['urn:example:ext']) A token is then rejected with JWT::InvalidCritError if crit lists anything other than the given extensions and b64, which the gem supports itself. Without the option nothing changes.
…alid nil and false entries got past the unknown extension check, because it tested the remaining entries for truthiness. crit now has to be an array of strings, so [nil], [false], [1] and nested arrays are rejected with 'Crit header should be an array of strings'. A crit header that is present but null is rejected the same way, and an unknown extension listed twice is named once. The README says that only unknown extensions depend on known_crit, as b64: false payloads always require crit: ['b64'], and a spec checks that crit is checked before the payload claims.
anakinj
marked this pull request as ready for review
November 29, 2026 11:07
This branch has not been deployed
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.
Description
RFC 7515 (section 4.1.11) says a token must be rejected if its
critheader lists an extension the recipient doesn't understand. ruby-jwt doesn't check this, and which extensions an application understands is up to the application, so this adds an opt-inknown_critoption:When
known_critis given, a token is rejected ifcritlists anything other than those extensions andb64, which the gem supports itself. Acritthat isn't an array of strings is rejected too, includingnull. A token withoutcritpasses. Without the option, nothing changes.JWT::Claims::KnownCrit, a new class next toJWT::Claims::Crit. It is registered as theknown_critclaim verifier, soverify_claims!,claim_errorsandvalid_claims?onEncodedTokensupport it.JWT.decode: runs the check after the signature has verified and before the payload claims. The option can be given with a symbol or string key, like the other decode options. It isn't checked whenverifyisfalse.Closes #815
Checklist
Before the PR can be merged be sure the following are checked:
fix: Reject tokens with too many segmentsPosted by Claude on behalf of @anakinj.