Repository navigation
Change logout from GET to POST to prevent cross-site session clearing - #211
Merged
Merged
Conversation
GET /logout accepted a cookie on any top-level navigation because the cookie is SameSite=Lax. The route is now POST-only. The nav dropdown uses a form submit instead of an anchor tag.
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.
Summary
GET /logoutandGET /api/logoutcleared the session, but aGETis sent with the session cookie on any top-level navigation (SameSite=Lax), so any page could cause a signed-in user to be logged out silently.Additionally, the logout handler set
MaxAge: 0on the cookie, which does not instruct the browser to delete it — it reverts to a session cookie that disappears only when the browser tab closes. This was a pre-existing bug surfaced while making the route change.Changes:
POST.MaxAge: -1in theLogouthandler, consistent with howAuthenticateclears the cookie.<form method="post">+<button>instead of<a href="/logout">.Verification
TestLogoutMethodRestriction:GET /api/logoutreturns405;POST /api/logoutsets the cookie withMaxAge = -1.go test -short ./www/api/ -run TestLogoutpasses.