fix(auth): protect logout from cross-site requests - #40
Closed
albertovincenzi wants to merge 1 commit into
Closed
Conversation
Contributor
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.
Problem
GET /api/auth/logoutcleared the session cookie and every/api/auth/*path bypassed the session middleware. A third-party page could navigate a signed-in operator to that URL and log them out. Using GET for a state-changing action also made crawlers/prefetchers capable of ending a session.Fix
POSTnullbody; cross-origin HTML forms cannot produce that content type and cross-origin JS must pass a CORS preflightGATE_DEV_EMAILmode and show same-origin failures in the sidebarReview notes for Alice
This PR is stacked after #39 in the auth chain (#15 → #31 → #39 → this PR) to keep each security issue isolated. The defence is layered: the route now requires a valid SameSite session, and its JSON extractor prevents same-site sibling origins from using a plain HTML form. Google login/callback remain reachable without a session by necessity. Existing bookmarks to the old GET logout endpoint will now receive 405.
Verification
cargo test --workspacecargo clippy --workspace --all-targets -- -D warningscargo fmt --checknpm run build