Repository navigation
Conversation
USER_UPDATED, MFA_CHALLENGE_VERIFIED and PASSWORD_RECOVERY all carry the current session, but the listener only used it for SIGNED_IN and TOKEN_REFRESHED. On any other event it set Authorization to the anon key, so storage, functions, realtime and any postgrest client built afterwards ran as anon, and the aal2 token from an MFA verify was never applied.
Pins the other half of the auth event change: once every event with a session uses its token, SIGNED_OUT (no session) has to drop back to the anon key on the client, auth, postgrest, storage and functions headers.
Gaurav-Kanse
left a comment
There was a problem hiding this comment.
I pulled this branch locally and reviewed the auth event flow and tests.
I traced PASSWORD_RECOVERY through gotrue_client.py: it's emitted from the same code path as SIGNED_IN, passing the same session object (_notify_all_subscribers("SIGNED_IN", session) / _notify_all_subscribers("PASSWORD_RECOVERY", session)). So the PR's logic of treating any event with a session identically is consistent with the current auth event implementation.
Ran the updated regression tests locally:
- sync: 6/6 passed
- async: 6/6 passed
I also ran the full test_client.py suites for both clients — 19 passed, 6 xfailed, with no failures.
The fix itself looks clean: replacing the per-event allowlist with a simple session-based check means newly introduced session-bearing events won't silently fall back to the anon key like USER_UPDATED and MFA_CHALLENGE_VERIFIED did before.
Thanks for the fix!
|
Thanks a lot for the thorough review @Gaurav-Kanse, and for tracing PASSWORD_RECOVERY through the gotrue client! @o-santi could you take a look when you get a chance? The branch is up to date with main, and the CI workflows are waiting on approval since it's from a fork. A couple of people have started asking to pick up #1670, so it'd be great to get this in and close that out. Happy to change anything you'd like. |
What kind of change does this PR introduce?
Bug fix, closes #1670
What is the current behavior?
_listen_to_auth_eventsonly uses the session token forSIGNED_IN/TOKEN_REFRESHED. OnUSER_UPDATED,MFA_CHALLENGE_VERIFIEDandPASSWORD_RECOVERYit setsAuthorizationto the anon key, so afterupdate_user()or an MFA verify, storage, functions, realtime and any fresh postgrest client run as anon. The aal2 token from MFA never gets applied.What is the new behavior?
Every event uses
session.access_tokenwhen there's a session and the anon key when there isn't (onlySIGNED_OUT), and the cached postgrest/storage/functions clients are always reset so they pick up the new header. That's the same thing supabase-js ends up doing.Tests: parametrized the existing
test_updates_the_authorization_header_on_auth_events(async + sync) over every event that carries a session, touched postgrest before the event so the cached client gets checked too, and added a functions header check. On main theUSER_UPDATED,MFA_CHALLENGE_VERIFIEDandPASSWORD_RECOVERYcases fail with the anon key; with the change they all pass.Additional context
Checked against a local
supabase startstack with RLS tables, before and after:(same output for the sync client)
cc @olirice @silentworks for review