Repository navigation
Description
A few more session bugs I hit while working on #394. Kept them out of that PR to keep it small. All on current master.
-
The 2-arg
RefreshTokendestroys whatever session is current (Client.cs L710-L743)It takes any tokens you hand it, but on
InvalidRefreshTokenit destroys the current session and its persisted copy, whoever the tokens belonged to. On success it overwritesCurrentSessionthe same way. fix(gotrue,supabase): session persistence end to end #394 guards the parameterless overload against this, not this one. It's the pathSignIn(SignInType.RefreshToken, ...)takes. -
SetSessiondestroys the session before it validates (Client.cs L542-L549)SetSession("", "")or a malformed JWT signs the user out and wipes the stored session on its way to throwing. The destroy should come after validation. -
The refresh timer can re-arm at zero after a success (TokenRefresh.cs L144-L163)
fix(gotrue,supabase): session persistence end to end #394 adds a 30 second floor after a failed refresh, but the success path has no floor, so a 200 with
expires_inof 0 or missing (orMaximumRefreshWaitTime = 0) reschedules immediately and never stops. About 24k requests in 1.2 seconds against a mock server. -
Most sign-in entry points destroy the session up front (Client.cs L174)
SignUp,SignIn(Provider),SignInAnonymously, bothSignInWithOtp, bothSignInWithSSO,SignInWithIdToken, bothVerifyOTP,VerifyTokenHash, andSetSessionabove. Password sign-in,ExchangeCodeForSessionandGetSessionFromUrldon't do this. On a cold start that's aSignedOutand a persistenceDestroySessionfor a session that was never there. If the sign-in then fails, the session the user already had is gone too. -
SignOutfiresSignedOuttwice (Client.cs L462-L473)Once from
UpdateSession(null)and once on its own, so a persistence handler gets twoDestroySessioncalls. -
A rejected refresh can still sign out the user that replaced it (Client.cs L831-L844)
fix(gotrue,supabase): session persistence end to end #394 makes the destroy conditional on the rejected token still being the current one, but the check, the destroy and the
SignedOutrun one after another with nothing holding them together. A sign-in landing in between gets destroyed, and even after the clear the lateSignedOutstill reaches the persistence listener, which wipes whatever session is stored by then and stops its refresh timer. The listeners react to the event, not to which session it was about, so the fix is ordering the notification against replacement, not a bigger lock.
One caveat: for 1, 2 and 4 the destroy is what the interface docs promise (IGotrueClient spells it out for SetSession and the 2-arg refresh, and the failed-signup tests assert it), so fixing them is a contract change, not just a bug fix.
The fixes for 1, 4 and 6 lean on the replaced-session guard from #394
edit: added 6, found in a later review pass on #394
Activity
[-]sign-in and refresh paths destroy sessions they shouldn't[/-][+]Sign-in and refresh paths destroy sessions they shouldn't[/+]