Repository navigation
fix(auth): reject a getClaims token whose alg does not fit the matched JWK - #1449
Open
AndroidPoet wants to merge 1 commit into
Open
AndroidPoet wants to merge 1 commit into
AndroidPoet wants to merge 1 commit into
Conversation
jan-tennert
approved these changes
Nov 1, 2026
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.
What
getClaimspicks the verifier from the token headeralgand never compares it with the JWK found for the headerkid. A token that saysES256but names an RSA key, or saysRS256but names an EC key, reaches the DER conversion for the wrong key type and fails withIllegalStateException: Param not foundinstead ofInvalidJwtException. Code that catchesInvalidJwtExceptionto reject bad tokens lets that one through as an unexpected error.While fixing it,
JWK.ktyturned out to throwClassCastExceptionon every read.JWK.ktis in thejwtpackage and does not import the module'sJsonObject.getValuedelegate, soby jwkresolves to the stdlibMapdelegate, which casts the rawJsonPrimitivetoKeyType.Fix
alg: the key'salgwhen it has one, otherwise itskty(andcrvP-256forES256). A mismatch throwsInvalidJwtExceptionand does not fall back to the Auth server.io.github.jan.supabase.auth.getValueinJWK.ktsoktydecodes toKeyType.supabase-flutter made the same check in supabase/supabase-flutter#2091.
Tests
testGetClaimsRejectsHeaderAlgNotMatchingKeyAlg: anES256header with the RSA key that declaresalg: RS256.testGetClaimsRejectsHeaderAlgNotMatchingKeyType: anRS256header with an EC key that has noalg, which also coverskty.Both fail without the fix (
IllegalStateException: Param not found). All 198 Auth JVM tests pass with it, and detekt is clean.No public API change.