Skip to content

Change logout from GET to POST to prevent cross-site session clearing - #211

Merged
dbaseqp merged 1 commit into
dbaseqp:mainfrom
tire-fire:fix/logout-as-post
Nov 13, 2026
Merged

dbaseqp merged 1 commit into
dbaseqp:mainfrom
tire-fire:fix/logout-as-post

Conversation

@tire-fire

Copy link
Copy Markdown
Contributor

Summary

GET /logout and GET /api/logout cleared the session, but a GET is 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: 0 on 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:

  • Both logout routes are now POST.
  • MaxAge: -1 in the Logout handler, consistent with how Authenticate clears the cookie.
  • The nav dropdown uses a <form method="post"> + <button> instead of <a href="/logout">.

Verification

TestLogoutMethodRestriction: GET /api/logout returns 405; POST /api/logout sets the cookie with MaxAge = -1.

go test -short ./www/api/ -run TestLogout passes.

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.
@dbaseqp
dbaseqp merged commit 1a0e0cd into dbaseqp:main Nov 13, 2026
5 checks passed
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.

2 participants