You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(auth): raise AuthInvalidJwtError for malformed JWTs in decode_jwt - #2056
Malformed tokens that passed base64 decoding escaped decode_jwt as a raw pydantic ValidationError or ValueError, so get_claims and set_session callers catching AuthError missed them.
decode_jwt validates the header and payload inside the try and maps every ValueError (base64, pydantic, non-ASCII) to AuthInvalidJwtError("Invalid JWT structure").
JWTHeader.typ is optional, as in RFC 7515.
Tests: decode_jwt cases for each malformed shape and a header without typ; async and sync get_claims raise AuthInvalidJwtError without any HTTP request.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 88846d12-7119-4000-a6c8-285766cc8789
Commits
Reviewing files that changed from the base of the PR and between c781578 and 84157f6.
Files selected for processing: 6
src/auth/tests/_async/conftest.py
src/auth/tests/_async/test_get_claims.py
src/auth/tests/_async/test_set_session.py
src/auth/tests/_sync/conftest.py
src/auth/tests/_sync/test_get_claims.py
src/auth/tests/_sync/test_set_session.py
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Invalid or malformed JWTs now produce a consistent authentication error instead of causing unexpected failures.
Claims retrieval rejects malformed tokens before sending a network request.
New Features
JWT headers without a typ value are now accepted, while valid decoded fields remain available.
decode_jwt now validates decoded JWT headers and payloads within its error-handling block. It converts ValueError raised during decoding or validation into AuthInvalidJwtError. JWTHeader.typ is optional and defaults to None. New tests cover malformed tokens and confirm that sync and async get_claims calls reject them before sending HTTP requests.
Possibly related PRs
supabase/supabase-py#1920: Maps ValueError from decode_jwt to AuthInvalidJwtError and tests malformed tokens in set_session.
Change: Bug fix
Merge Risk: Minimal · previous review c7815
Malformed JWTs now raise AuthInvalidJwtError instead of raw validation errors, so callers catching AuthError handle them correctly. No merge-blocking risk was identified.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: ce363e5d-9117-4c1e-b523-3daf5a2a3a9d
Commits
Reviewing files that changed from the base of the PR and between 569e6fa and c781578.
Files selected for processing: 5
src/auth/src/supabase_auth/helpers.py
src/auth/src/supabase_auth/types.py
src/auth/tests/_async/test_get_claims.py
src/auth/tests/_sync/test_get_claims.py
src/auth/tests/test_helpers.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
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
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.
Malformed tokens that passed base64 decoding escaped
decode_jwtas a raw pydanticValidationErrororValueError, soget_claimsandset_sessioncallers catchingAuthErrormissed them.decode_jwtvalidates the header and payload inside thetryand maps everyValueError(base64, pydantic, non-ASCII) toAuthInvalidJwtError("Invalid JWT structure").JWTHeader.typis optional, as in RFC 7515.decode_jwtcases for each malformed shape and a header withouttyp; async and syncget_claimsraiseAuthInvalidJwtErrorwithout any HTTP request.SDK-2819