Repository navigation
Treat a login cookie with an expired access token as logged out - #1057
Open
TanmayS0406 wants to merge 1 commit into
Open
TanmayS0406 wants to merge 1 commit into
TanmayS0406 wants to merge 1 commit into
Conversation
The WebApp renews the login cookie while the user is active, but the access token stored in it expires after 2 hours and is never renewed. Once it has, the WebApp still shows the user as logged in while the APIs treat them as anonymous: reading the basket succeeds (it is anonymous and returns an empty basket) but any write fails with RpcException Unauthenticated, so adding to the cart ends in a 500. Reject the cookie when its access token has expired, so the user is signed out and asked to log in again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Related to #9.
Problem
The WebApp keeps the user signed in with a cookie that is renewed while they are active, but the access token stored inside it expires after 2 hours (
AccessTokenLifetimeinIdentity.API) and is never renewed. Once it has expired:GetBasketsucceeds, because it is[AllowAnonymous]and returns an empty basket when there is no user;UpdateBasketandDeleteBasketfail withRpcException: Status(StatusCode="Unauthenticated", Detail="The caller is not authenticated."), so adding to the cart ends in a 500.That matches what is described in #9 (logged in,
GetBasketAsyncsucceeds,UpdateBasketAsyncfails withUnauthenticated, fixed by logging out and in). The reporter there describes a non-expired token, so I can't say this is the only way to reach that state, which is why this is "related to" and not "fixes".Change
OnValidatePrincipalon the cookie now rejects the principal and signs out when theexpires_attoken stored in the cookie is in the past. The user is then treated as logged out and asked to log in again.Verification
Reproduced and fixed by running Identity, Basket, Catalog, Ordering and the WebApp locally and driving the site with Playwright. To avoid waiting 2 hours, I temporarily set the
webappclient'sAccessTokenLifetimeto 10 seconds (not part of this PR), logged in asalice, waited past the token's expiry plus the API's 5 minute clock skew, then added an item to the cart.main/item/1returns 500,Unauthenticatedin the WebApp and Basket API logsUnauthenticatedin the logsThe existing Playwright suite (browse, cart, checkout) passes with the normal 2 hour lifetime.
Not covered
Application.UnitTestshas no reference to the WebApp. I can add one if you prefer to expose the handler for testing.🤖 Generated with Claude Code