feat: fallback to trying all JWKS keys when kid does not match#893
Open
liudonggalaxy wants to merge 1 commit into
Open
feat: fallback to trying all JWKS keys when kid does not match#893liudonggalaxy wants to merge 1 commit into
liudonggalaxy wants to merge 1 commit into
Conversation
7790b09 to
4482c61
Compare
5835873 to
a9c210a
Compare
Add a configurable fallback for OIDC ID token verification when the token's kid header does not match any key in the provider's JWKS. Behavior on InvalidKeyIdError: 1. Refresh JWKS via fetch_jwk_set(force=True) to handle key rotation 2. Retry kid-based decode with refreshed keyset 3. If should_try_all_keys() returns True, try each key individually; otherwise re-raise InvalidKeyIdError (default, backwards-compatible) Co-authored-by: Copilot <[email protected]>
a9c210a to
4ee4def
Compare
Member
|
Is there a real use case? I don't think it is a good idea go accept non-matched keys. |
Contributor
Author
Yes. Some identity providers do not include The |
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.
What kind of change does this PR introduce?
This is a feature implementation that adds a configurable fallback for OIDC ID token verification when the token's
kidheader does not match any key in the provider's JWKS.What is the current behavior?
When
jwt.decode()raisesInvalidKeyIdError, the code refreshes the JWKS and retries. If the kid still does not match after refresh,InvalidKeyIdErroris raised with no way to recover. This breaks integration with OIDC providers whose JWKS keys lack akidfield or usekidvalues that do not match the token header.What is the new behavior?
On
InvalidKeyIdError:fetch_jwk_set(force=True)to handle key rotationshould_try_all_keys()returnsTrue, try each key individually; otherwise re-raiseInvalidKeyIdError(default, backwards-compatible)Subclasses can override
should_try_all_keys()to enable the brute-force fallback:Checklist
prek.pragma: no cover