[PR #5322] [CLOSED] fix(oauth): Certain oauth providers won't set state cookie #5926

Closed
opened 2026-03-13 12:41:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5322
Author: @ping-maxwell
Created: 10/15/2025
Status: Closed

Base: canaryHead: fix/oauth-not-set-state-cookie


📝 Commits (3)

  • cd87ca9 fix(oauth): Certain oauth providers won't set state cookie
  • 939e9b6 fix: lint
  • d678100 Merge branch 'canary' into fix/oauth-not-set-state-cookie

📊 Changes

1 file changed (+2 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/oauth2/state.ts (+2 -0)

📄 Description

todo: discuss with Beka about this.

The issue arises during the OAuth flow when using Apple Sign-In or similar providers that rely on POST callbacks. The state parameter validation fails because the state cookie is not included in the callback request. A workaround suggests using SameSite=None and secure=true for cookies, but this may compromise security for other session cookies.

issue: https://github.com/better-auth/better-auth/issues/5243

linear: https://linear.app/better-auth/issue/ENG-307/oauth-providers-fail-with-state-mismatch-error-when-using-post


Summary by cubic

Set the OAuth state cookie to SameSite=None and Secure so it’s sent on POST callbacks (e.g., Apple Sign-In), fixing state mismatch errors. This change is limited to the state cookie only.

  • Bug Fixes
    • Create the state cookie with sameSite: "none" and secure: true to ensure it’s included in POST callback requests.
    • Scoped to the state cookie only; other session cookies are unchanged. Addresses Linear ENG-307.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5322 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/15/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/oauth-not-set-state-cookie` --- ### 📝 Commits (3) - [`cd87ca9`](https://github.com/better-auth/better-auth/commit/cd87ca921c9a2366c2c576f48b0a8334bd5adb85) fix(oauth): Certain oauth providers won't set `state` cookie - [`939e9b6`](https://github.com/better-auth/better-auth/commit/939e9b67025db44562a4c5b38b3fcc5c494b059b) fix: lint - [`d678100`](https://github.com/better-auth/better-auth/commit/d678100f0eccf031a580e0f810621e60e62084b6) Merge branch 'canary' into fix/oauth-not-set-state-cookie ### 📊 Changes **1 file changed** (+2 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/state.ts` (+2 -0) </details> ### 📄 Description todo: discuss with Beka about this. The issue arises during the OAuth flow when using Apple Sign-In or similar providers that rely on `POST` callbacks. The state parameter validation fails because the state cookie is not included in the callback request. A workaround suggests using `SameSite=None` and `secure=true` for cookies, but this may compromise security for other session cookies. issue: https://github.com/better-auth/better-auth/issues/5243 linear: https://linear.app/better-auth/issue/ENG-307/oauth-providers-fail-with-state-mismatch-error-when-using-post <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Set the OAuth state cookie to SameSite=None and Secure so it’s sent on POST callbacks (e.g., Apple Sign-In), fixing state mismatch errors. This change is limited to the state cookie only. - **Bug Fixes** - Create the state cookie with sameSite: "none" and secure: true to ensure it’s included in POST callback requests. - Scoped to the state cookie only; other session cookies are unchanged. Addresses Linear ENG-307. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:41:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5926