Skip to content

Set SameSite=None on the OAuth state cookie so form_post callbacks keep it - #2946

Open
RaphaelFakhri wants to merge 2 commits into
instantdb:mainfrom
RaphaelFakhri:fix-oauth-cookie-samesite
Open

RaphaelFakhri wants to merge 2 commits into
instantdb:mainfrom
RaphaelFakhri:fix-oauth-cookie-samesite

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 19, 2026 •

Copy link
Copy Markdown

Fixes #2892

Summary

/runtime/oauth/start sets the __session state cookie without a SameSite attribute, so browsers apply the Lax default. The generic OAuth client asks providers for response_mode=form_post, which makes the callback a cross-site POST to /runtime/oauth/callback. Browsers do not send Lax cookies 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: set SameSite=None on the state cookie whenever it is Secure. In dev, where the cookie is not Secure, the attribute stays unset, because browsers reject SameSite=None without Secure, and an explicit Lax would turn off Chrome's "Lax + POST" allowance.
  • server/test/instant/runtime/routes_test.clj: add a test that calls /runtime/oauth/start through the handler and checks that the Set-Cookie header includes Secure and SameSite=None.

Testing

clojure -M:test -v instant.runtime.routes-test/oauth-start-cookie-is-sent-on-cross-site-callback
  • Without the change: 1 failure. The header is __session=instantdb_...; HttpOnly; Secure; Expires=...; Path=/runtime/oauth.
  • With the change: 0 failures. The header includes SameSite=None.
  • clojure -M:test -n instant.runtime.routes-test: 25 tests, 256 assertions, 0 failures.
  • clojure -M:lint on both files: 0 errors, 0 warnings.

…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
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The OAuth route adds SameSite=None to the session cookie outside :dev. A new test checks the HTTPS OAuth-start response status and cookie attributes.

Changes: OAuth session cookie

Layer / File(s) Summary
Set and verify OAuth cookie attributes
server/src/instant/runtime/routes.clj, server/test/instant/runtime/routes_test.clj
Outside :dev, the route sets Secure and SameSite=None on the session cookie. In :dev, it does not set the SameSite attribute. The test checks that an HTTPS OAuth-start response returns status 302 and sets a Secure session cookie with SameSite=None.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 2954f

This change makes the OAuth state cookie survive cross-site form_post callbacks in non-development environments, and leaves development behavior unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the OAuth state cookie gets SameSite=None so form_post callbacks still send it. The routes.clj change and the new test both match this. The title is specific and accur…
Linked Issues check Passed Issue #2892 is closed and is the only directly linked issue. Under the active-target rules it supplies background only, so no linked-issue coding requirements apply. The issue's stated expectation (`S…
Out of Scope Changes check Passed The reviewed changes stay within the OAuth start state-cookie behavior. The routes.clj change alters only the cookie options in oauth-start: :same-site :none when secure, and no attribute in dev…
Description check Passed The description states it fixes issue #2892 and explains the change: the OAuth state cookie on /runtime/oauth/start lacks a SameSite attribute, so cross-site form_post callbacks drop it. It lists the …
Full details: Title check

Explanation

The title names the main change: the OAuth state cookie gets SameSite=None so form_post callbacks still send it. The routes.clj change and the new test both match this. The title is specific and accurate.

Full details: Linked Issues check

Explanation

Issue #2892 is closed and is the only directly linked issue. Under the active-target rules it supplies background only, so no linked-issue coding requirements apply. The issue's stated expectation (SameSite=None; Secure on the __session cookie for form_post callbacks) is still met as a reference point. At reviewed head 2954f04, oauth-start in server/src/instant/runtime/routes.clj sets :secure when the env is not :dev, and adds :same-site :none only in that branch. The dev branch leaves SameSite unset. The change since the previous review (2cde2fa) removed the earlier explicit :lax in dev, so the previous conclusion that dev keeps :lax no longer holds. The current code still meets the issue expectation outside dev. The added handler test in server/test/instant/runtime/routes_test.clj was not readable in this review. Its existence and assertions rely on the PR description and raw summary, not on a read of the blob.

Full details: Out of Scope Changes check

Explanation

The reviewed changes stay within the OAuth start state-cookie behavior. The routes.clj change alters only the cookie options in oauth-start: :same-site :none when secure, and no attribute in dev. Its comment ties the choice to the form_post callback and Chrome's Lax+POST allowance. The test file change, per the PR description and raw summary, adds one /runtime/oauth/start regression test. The test file blob was not readable here, so its exact content is unverified. No unrelated implementation changes were identified in the readable evidence.

Full details: Description check

Explanation

The description states it fixes issue #2892 and explains the change: the OAuth state cookie on /runtime/oauth/start lacks a SameSite attribute, so cross-site form_post callbacks drop it. It lists the changes to routes.clj and routes_test.clj, plus test and lint results. It is clearly related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7ea9361b-e420-406d-9d5e-2524ae828f5e
Commits

Reviewing files that changed from the base of the PR and between 2cde2fa and 2954f04.

Files selected for processing: 1

  • server/src/instant/runtime/routes.clj

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@verveguy

Copy link
Copy Markdown
Contributor

We're taking this ahead of upstream in our self-hosted fork, cherry-picked unchanged: liminisapp#3. instant.runtime.routes-test passes (25 tests).

A review on our side raised a development-only point. Setting Lax explicitly turns off Chrome's two-minute "Lax + POST" allowance, which only applies to cookies with no SameSite. So quick generic-provider sign-ins over plain HTTP in dev may now fail where they used to work. Leaving the attribute unset when the cookie isn't Secure would keep the old dev behaviour. Production (Secure) is unaffected either way.

If this PR changes, we'll take the new head.

An explicit SameSite=Lax turns off Chrome's two-minute "Lax + POST"
allowance, which only applies to cookies without a SameSite attribute,
so form_post callbacks over plain HTTP in dev stopped receiving the
cookie. Set SameSite=None only when the cookie is Secure.
@RaphaelFakhri

Copy link
Copy Markdown
Author

Good catch, thanks. An explicit Lax does turn off Chrome's "Lax + POST" allowance, so the dev flow over plain HTTP was worse than before. 2954f04 sets SameSite=None only when the cookie is Secure and leaves the attribute unset otherwise, as it was before this PR.

The emitted headers, checked with ring-core 1.13.0:

  • dev: __session=...; HttpOnly; Path=/runtime/oauth
  • non-dev: __session=...; HttpOnly; Secure; Path=/runtime/oauth; SameSite=None

The production path and oauth-start-cookie-is-sent-on-cross-site-callback are unchanged. clj-kondo reports 0 errors and 0 warnings on routes.clj.

This branch has not been deployed

No deployments
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

2 participants