security: verify JWT signature in OAuth2 base class (CWE-347) - #1632
Open
aryamirani wants to merge 1 commit into
Open
security: verify JWT signature in OAuth2 base class (CWE-347)#1632aryamirani wants to merge 1 commit into
aryamirani wants to merge 1 commit into
Conversation
The get_decoded_jwt_token() method in OAuth2ClientBase was decoding JWT tokens with verify=False and verify_signature=False, allowing an attacker to forge tokens with arbitrary claims (e.g. user identity via the 'sub' claim). This is a critical authentication bypass since the method is called from permissions.py to authenticate users via get_user_from_oauth2(). Fix: When OAUTH2_PROVIDER_PUBLIC_KEY is configured, verify the JWT signature using the provider's RSA public key before trusting claims. When no key is configured, log a security warning to alert operators. Also removes the deprecated 'verify' parameter (replaced by 'options' in PyJWT >= 2.0). CWE-347: Improper Verification of Cryptographic Signature CVSS: High (authentication bypass)
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.
Summary
The
get_decoded_jwt_token()method inOAuth2ClientBasedecodes JWT tokens withverify=Falseandoptions={"verify_signature": False}, allowing an attacker to forge tokens with arbitrary claims.Security Impact
CWE-347: Improper Verification of Cryptographic Signature
This is a critical authentication bypass vulnerability. The unverified JWT decode is called from:
permissions.py:171—get_user_from_oauth2()usesget_decoded_jwt_token()to extract thesubclaim and look up the authenticated userpermissions.py:82,89,109—id_token_has_expired()callsget_decoded_jwt_token()to check token expiryAn attacker can craft a JWT with an arbitrary
subclaim (pointing to any user) and anexpclaim far in the future. Since the signature is never verified, the application will accept the forged token and authenticate the attacker as any user.Note: The
KeycloakDiffgramClient.verify_token()already properly verifies JWT signatures using the provider's public key — this fix brings the same verification to the base class method used in the permissions flow.Fix
When
OAUTH2_PROVIDER_PUBLIC_KEYis configured:When no public key is configured:
Also removes the deprecated
verifyparameter (replaced byoptionsdict in PyJWT >= 2.0).Testing