fix: stable CSRF cookie across /login re-renders + open favicon route#165
Merged
Conversation
WIP preserved from the working tree (was uncommitted on develop): reuse the browser's existing well-formed tb_csrf cookie instead of minting a fresh one per render (a background /login re-render rotated the cookie under the form), open /favicon.ico so the icon probe never bounces through /login, and cover both with tests.
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.
Two intertwined login-flow fixes (found while operating the dashboard):
GET /loginused to mint a fresh token per render and rotate thetb_csrfcookie — so any background request that got auth-redirected to/login(typically the browser's/favicon.icoprobe) re-rendered the page and rotated the cookie under the form the user was looking at; every submit then 403'd, forever. The render now REUSES the browser's existing cookie when it matches the exact shape we mint (token_urlsafe(32)→ 43 urlsafe chars, enforced by regex so an arbitrary value can never be echoed back into the form), and only mints otherwise — the standard stable double-submit pattern./favicon.icois an open route (308 →/static/favicon.svg) so the icon probe never bounces through the auth redirect in the first place;login.htmlalso declares the SVG icon explicitly.Tests: the favicon-race regression (form token from the first render still authenticates after a background re-render), the open-route contract, and the malformed-cookie rejection (a
<script>cookie is replaced, never echoed).🤖 Generated with Claude Code