Repository navigation
fix: keep the CSRF token stable per browser and retry once on CSRF_INVALID - #8
Merged
Merged
Conversation
…VALID Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
On prod,
POST /api/v1/integrations/knotree-registry/authorize(and any mutation) can fail with403 CSRF_INVALID.Cause: the CSRF cookie is shared by every tab, but each tab caches its own token in memory. Any later call to
/auth/csrf(another tab, a reload, signing in again) overwrites the cookie, so the older tab sends a stale header.Fix:
/auth/csrfreuses the browser's existing, well-formed CSRF cookie instead of minting a new one every time.apiRequestresets its cached token and retries once onCSRF_INVALID/CSRF_REQUIRED.This commit was pushed to #7 after that PR had already merged, so it was not included in that deploy.
Test plan
cargo testfor the API against Postgres: 119 passed, including the newcsrf_reuses_the_browsers_current_token.src/lib/api.test.ts: a stale token gets refreshed and the request is retried once.tsc --noEmit🤖 Generated with Claude Code