Skip to content

fix(backend): set the session cookie flags explicitly - #349

Merged
arrzdev merged 2 commits into
mainfrom
fix/explicit-session-cookie-flags
Nov 17, 2026
Merged

arrzdev merged 2 commits into
mainfrom
fix/explicit-session-cookie-flags

Conversation

@arrzdev

@arrzdev arrzdev commented Nov 17, 2026

Copy link
Copy Markdown
Owner

What and why

better-auth only adds Secure to the session cookie when BETTER_AUTH_URL starts with https://. Production is https, so the cookie is Secure today, but nothing stops an http URL from quietly dropping the flag, and no test could notice because the test env uses an http base URL.

The auth config now sets Secure, HttpOnly and SameSite=Lax through advanced.defaultCookieAttributes. It does not use useSecureCookies, because that also renames the cookie to __Secure-….

The game signs in with bearer tokens, so making the cookie Secure on http dev doesn't change dev sign-in.

How to verify

  • pnpm --filter @repo/backend exec vitest run src/http/routes/auth.routes.test.ts -t cookie: the cookie test now also checks Secure. It fails on main (http base URL) and passes here.
  • After deploy: sign in against production and check that the set-cookie on /api/v1/auth/sign-in/username contains Secure; HttpOnly; SameSite=Lax.

UI quality gate

Does not apply: backend only.

@arrzdev
arrzdev merged commit a18618c into main Nov 17, 2026
5 checks passed
@arrzdev
arrzdev deleted the fix/explicit-session-cookie-flags branch November 17, 2026 05:22
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