Skip to content

Set SameSite=None on the OAuth state cookie (upstream #2946) - #3

Merged
verveguy merged 1 commit into
self-hosted-patchesfrom
upstream-pr/2946-oauth-state-samesite
Nov 13, 2026
Merged

verveguy merged 1 commit into
self-hosted-patchesfrom
upstream-pr/2946-oauth-state-samesite

Conversation

@verveguy

@verveguy verveguy commented Nov 13, 2026 •

Copy link
Copy Markdown

Carries upstream instantdb#2946 (by RaphaelFakhri; fixes instantdb#2892), cherry-picked unchanged from 2cde2fa with -x.

What it fixes. /runtime/oauth/start sets the __session state cookie without a SameSite attribute, so browsers treat it as Lax. The generic OAuth client asks providers for response_mode=form_post, so the callback is a cross-site POST, and browsers don't send Lax cookies on those. Sign-ins that take longer than about two minutes, such as with 2FA or a passkey prompt, then fail with "Missing cookie." This sets SameSite=None whenever the cookie is Secure. In dev, where the cookie isn't Secure, it stays Lax.

Tests (OrbStack on the Mac, arm64):

  • instant.runtime.routes-test: 25 tests, 256 assertions, 0 failures.

Tracking. The upstream head we took is recorded. If the upstream PR changes, we'll take the new head; if upstream merges it, we'll drop this commit when we rebase.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HRKkuGrp63pNCgPK1hVdC7

…ep it

The runtime OAuth flow asks providers for response_mode=form_post, so the
callback arrives as a cross-site POST. Without a SameSite attribute,
browsers treat the __session cookie as Lax and drop it on that POST once
the sign-in takes longer than two minutes (2FA, passkeys), and the
callback fails with "Missing cookie."

Fixes instantdb#2892

(cherry picked from commit 2cde2fa)
Copilot AI balanced review requested due to automatic review settings November 13, 2026 14:06

@liminisapp-pruefer liminisapp-pruefer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read both staged entries in full: the routes.clj change and the new routes_test.clj test. The fix sets :same-site :none on the OAuth state cookie whenever it is Secure, and :lax otherwise. That follows from the described cause: the form_post callback is a cross-site POST, which browsers don't send Lax cookies on. SameSite=None is only emitted together with Secure, which browsers require. The cookie is still HttpOnly and scoped to /runtime/oauth, and the state check is unchanged, so I see no new security exposure. The new test checks the Set-Cookie header for Secure and SameSite=None, so it fails if the fix is removed.

I didn't run the tests; the PR description reports 25 passing in instant.runtime.routes-test. I found no defects.

PRUEFER_COVERAGE: complete

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Explicit SameSite=Lax breaks development sign-ins using cross-site form_post callbacks by withholding the cookie; leave SameSite unset in development and apply SameSite=None only in the secure branch.

1 open issue
What changed in this PR

Carries upstream instantdb#2946 to fix OAuth state-cookie delivery on cross-site POST callbacks, addressing delayed sign-in failures reported in instantdb#2892.

Changes:

  • Sets SameSite=None on secure OAuth state cookies and explicit Lax on non-secure development cookies.
  • Adds a handler-level regression test checking the serialized cookie’s Secure and SameSite=None attributes.
File Description
server/​test/​instant/​runtime/​routes_test.clj Tests OAuth start response status and cookie attributes.
server/​src/​instant/​runtime/​routes.clj Sets the OAuth state cookie’s SameSite policy based on its Secure flag.

Review effort: Balanced

Comment on lines +269 to +280
(let [secure? (not= :dev (config/get-env))]
{:http-only true
;; Don't require https in dev
:secure secure?
;; The provider POSTs back to the callback
;; (response_mode=form_post), so the cookie
;; has to be sent on a cross-site request.
;; Browsers reject SameSite=None without Secure.
:same-site (if secure? :none :lax)
:expires cookie-expires
;; matches everything under the subdirectory
:path "/runtime/oauth"})))))
@verveguy
verveguy merged commit 902cc9c into self-hosted-patches Nov 13, 2026
1 check 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.

OAuth web redirect fails with "Missing cookie." — __session lacks SameSite=None while the flow uses response_mode=form_post

3 participants