Repository navigation
Set SameSite=None on the OAuth state cookie (upstream #2946) - #3
Conversation
…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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
🟡 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=Noneon secure OAuth state cookies and explicitLaxon non-secure development cookies. - Adds a handler-level regression test checking the serialized cookie’s
SecureandSameSite=Noneattributes.
| 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
| (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"}))))) |

Carries upstream instantdb#2946 (by RaphaelFakhri; fixes instantdb#2892), cherry-picked unchanged from 2cde2fa with
-x.What it fixes.
/runtime/oauth/startsets the__sessionstate cookie without aSameSiteattribute, so browsers treat it asLax. The generic OAuth client asks providers forresponse_mode=form_post, so the callback is a cross-site POST, and browsers don't sendLaxcookies 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 setsSameSite=Nonewhenever the cookie isSecure. In dev, where the cookie isn'tSecure, it staysLax.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