Skip to content

fix(auth): raise AuthInvalidJwtError for non-JWT access tokens in set_session - #2059

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2747-auth-set-session-non-jwt-token
Nov 16, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-2747-auth-set-session-non-jwt-token

Conversation

@spydon

@spydon spydon commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes SDK-2747. Port of the v2 fix in #1920.

  • set_session no longer indexes access_token.split(".")[1] before decoding, so a token without a dot raises AuthInvalidJwtError instead of IndexError.
  • Adds the no-dots and two-parts cases to the malformed JWT test, async and generated sync.

…_session

`set_session` indexed `access_token.split(".")[1]` before decoding, so a
token without a dot raised `IndexError` instead of `AuthInvalidJwtError`.
Let `decode_jwt` validate the structure instead. SDK-2747
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved session token validation so malformed JWTs, including tokens without three parts, are rejected before any requests are made.

_set_session now attempts JWT decoding for every nonempty access token. Async and sync tests add opaque and two-part tokens, and verify that malformed tokens raise AuthInvalidJwtError without making requests.

Possibly related PRs

Change: Bug fix

Merge Risk: Minimal · up to 8533a

This change makes set_session raise the documented AuthInvalidJwtError for malformed access tokens instead of an IndexError. Tests cover the new malformed-token forms. No concrete merge-blocking risk was found.

- [ ] 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81f67953-5f69-4002-8d3a-56ed9b520ac3
Commits

Reviewing files that changed from the base of the PR and between a8fe898 and 8533a88.

Files selected for processing: 3

  • src/auth/src/supabase_auth/client.py
  • src/auth/tests/_async/test_set_session.py
  • src/auth/tests/_sync/test_set_session.py
Files skipped from review as they are similar to previous changes: 1

  • src/auth/src/supabase_auth/client.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

@spydon
spydon merged commit 27dcc04 into main Nov 16, 2026
26 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2747-auth-set-session-non-jwt-token branch November 16, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant