Skip to content

fix(security): send kops_refresh cookie on every fetch (bug 10 part B) - #170

Merged
Randycarteronion merged 1 commit into
however-yir:mainfrom
Randycarteronion:fix/chat-credentials-include
Sep 7, 2026
Merged

Randycarteronion merged 1 commit into
however-yir:mainfrom
Randycarteronion:fix/chat-credentials-include

Conversation

@Randycarteronion

Copy link
Copy Markdown
Collaborator

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:

  • Attach the kops_refresh cookie automatically on every /auth/* call (including /auth/refresh)
  • Drop the cookie on same-origin non-/auth paths (Path attribute is /auth only)

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).

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.
@Randycarteronion
Randycarteronion merged commit 799f1b6 into however-yir:main Sep 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant