fix(pwa): include the CSRF token in the app-bar sign-out form#52
Open
khipu-agent wants to merge 1 commit into
Open
fix(pwa): include the CSRF token in the app-bar sign-out form#52khipu-agent wants to merge 1 commit into
khipu-agent wants to merge 1 commit into
Conversation
The global csrfGuard rejects any browser POST without a matching _csrf field, and the sign-out form rendered by appBar() didn't carry one — so clicking "Sign out" always returned 403 and the session stayed alive. Thread req.csrfToken into appBar() like every other form already does.
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.
Bug
The global
csrfGuardrejects every browser POST that doesn't carry a_csrffield matching themc_csrfcookie. Every form in the app includes one viacsrfInput(req)— except the Sign out form rendered byappBar()insrc/lib/html.mjs, which posts to/auth/logoutwith no token. So clicking "Sign out" anywhere in the app always returns403 bad csrf tokenand the session stays alive. Signing out is impossible from the UI.Repro: sign in, open the dashboard (or Settings, the CLI-authorize page, or an approval page), click "Sign out" → 403. The new test in
apps/pwa/test/logout-csrf.test.mjsrenders the dashboard with a real session and asserts the sign-out form carries the token — it fails on current code.Fix
appBar()now takes the request's CSRF token as a third argument and renders it as a hidden_csrfinput, exactly like the other forms; the five call sites passreq.csrfToken. The guard itself is unchanged (a tokenless POST still gets 403, covered by the second test).Tests
New integration tests in
apps/pwa/test/logout-csrf.test.mjs:_csrfvalue, and submitting it logs out (302 + session row deleted);/auth/logoutwithout a token is still rejected with 403 and the session survives.Full suite: 166/166 green.