Repository navigation
Set SameSite=None on the OAuth state cookie so form_post callbacks keep it - #2946
RaphaelFakhri wants to merge 1 commit into
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Fixes #2892
Summary
/runtime/oauth/startsets the__sessionstate cookie without aSameSiteattribute, so browsers apply theLaxdefault. The generic OAuth client asks providers forresponse_mode=form_post, which makes the callback a cross-site POST to/runtime/oauth/callback. Browsers do not sendLaxcookies on cross-site POSTs, except for Chrome's short-lived "Lax + POST" allowance on cookies younger than two minutes. Sign-ins that take longer, such as 2FA or passkey prompts, fail with{"type":"oauth-error","error":"Missing cookie."}.Changes
server/src/instant/runtime/routes.clj: setSameSite=Noneon the state cookie whenever it isSecure. In dev, where the cookie is notSecure, it staysLax, because browsers rejectSameSite=NonewithoutSecure.server/test/instant/runtime/routes_test.clj: add a test that calls/runtime/oauth/startthrough the handler and checks that theSet-Cookieheader includesSecureandSameSite=None.Testing
__session=instantdb_...; HttpOnly; Secure; Expires=...; Path=/runtime/oauth.SameSite=None.clojure -M:test -n instant.runtime.routes-test: 25 tests, 256 assertions, 0 failures.clojure -M:linton both files: 0 errors, 0 warnings.