fix(security): send kops_refresh cookie on every fetch (bug 10 part B) - #170
Merged
Randycarteronion merged 1 commit intoSep 7, 2026
Conversation
With PR however-yir#168 the backend now delivers the long-lived refresh token as a kops_refresh HttpOnly + Path=/auth + SameSite=Strict cookie. This PR is the matching front-end change: every fetch in frontend/src/api/client.ts now sets credentials: 'include' so the browser automatically attaches the cookie on cross-origin requests to /auth/* (and any other endpoints served from the same origin). For apiKey-based /auth/token and /auth/refresh the cookie goes along on the same-origin request automatically; for cross-origin deployments the front-end has to be served from a parent domain of the API host, or the operator has to relax SameSite to 'Lax' on the API side. The backend cookie sets SameSite=Strict as the safer default. 19 fetch call sites are updated. The change is mechanical and the behaviour is governed by the browser: when the access token expires (2h by default), the front-end calls /auth/refresh, the browser attaches the cookie automatically, and a new access token comes back. The user no longer has to re-enter anything.
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.
Part B of the bug 10 fix. PR #168 added the kops_refresh HttpOnly + Path=/auth + SameSite=Strict cookie on the backend. This PR flips the front-end fetch helper to credentials: 'include' so the browser sends the cookie automatically.
19 fetch call sites in frontend/src/api/client.ts are updated. With credentials: 'include' the browser will:
The user no longer has to re-enter anything: the access token expires (default 2h), the front-end calls /auth/refresh, the browser attaches the cookie, the backend mints a new access token, the cycle continues until the refresh token itself expires.
Behaviour unchanged when the cookie is not set (eg dev mode without a Secure cookie and the page is served over plain HTTP).