[PR #8949] [MERGED] fix: cookie store strategy should verify oauth state #25219

Closed
opened 2026-04-15 22:46:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8949
Author: @ping-maxwell
Created: 4/4/2026
Status: Merged
Merged: 4/9/2026
Merged by: @gustavovalverde

Base: mainHead: fix/validate-oauth-state


📝 Commits (9)

📊 Changes

5 files changed (+108 additions, -2 deletions)

View changed files

.changeset/famous-banks-open.md (+5 -0)
📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+58 -0)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+9 -0)
📝 packages/better-auth/src/social.test.ts (+2 -0)
📝 packages/better-auth/src/state.ts (+34 -2)

📄 Description

Summary

When account.storeStateStrategy is "cookie", the OAuth callback only decrypted the oauth_state cookie and checked expiry. It did not verify that the state query parameter matched the nonce issued at sign-in, which broke CSRF binding for the authorization response.
This change stores the issued state (oauthState) inside the persisted payload (encrypted cookie and, for the database strategy, the verification record value) and rejects the callback unless the incoming state matches. The OAuth proxy path that decrypts the passthrough cookie now also checks oauthState against the inner state when present.


🔄 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/8949 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 4/4/2026 **Status:** ✅ Merged **Merged:** 4/9/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `fix/validate-oauth-state` --- ### 📝 Commits (9) - [`71c3eb3`](https://github.com/better-auth/better-auth/commit/71c3eb31aaaeb141bc540bdeeca0a8261eaebba2) fix: validate oauth state - [`2875e63`](https://github.com/better-auth/better-auth/commit/2875e6321dc00539843a8a407905c25d9a33f590) chore: lint - [`7e02435`](https://github.com/better-auth/better-auth/commit/7e02435248e9e80549e1f92c026fdbf2a61358fa) Create famous-banks-open.md - [`d3d559d`](https://github.com/better-auth/better-auth/commit/d3d559d65c0e0dd5544d7f7ce74a566468a85450) chore: fix ci - [`528b59b`](https://github.com/better-auth/better-auth/commit/528b59b787df09eeb5e67abb177f5283744ee281) fix: stronger unit tests - [`b4a3b94`](https://github.com/better-auth/better-auth/commit/b4a3b94ba88024fff97f25d94f348f8bded26bd6) Update social.test.ts - [`ec1935b`](https://github.com/better-auth/better-auth/commit/ec1935b5a3b036f6242e9290ad750a07e0d2d2f1) chore: update message - [`aa5f907`](https://github.com/better-auth/better-auth/commit/aa5f90799ca55d0a73ad65efeedf7cc753f1a8fc) chore: use error page - [`b461c7c`](https://github.com/better-auth/better-auth/commit/b461c7c76bc6d5ccf0162ca5e2c2958523f6e2f8) chore: clarify changeset as security fix (CSRF) ### 📊 Changes **5 files changed** (+108 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/famous-banks-open.md` (+5 -0) 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+58 -0) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+9 -0) 📝 `packages/better-auth/src/social.test.ts` (+2 -0) 📝 `packages/better-auth/src/state.ts` (+34 -2) </details> ### 📄 Description ### Summary When `account.storeStateStrategy` is `"cookie"`, the OAuth callback only decrypted the `oauth_state` cookie and checked expiry. It did **not** verify that the `state` query parameter matched the nonce issued at sign-in, which broke CSRF binding for the authorization response. This change stores the issued state (`oauthState`) inside the persisted payload (encrypted cookie and, for the database strategy, the verification record value) and rejects the callback unless the incoming `state` matches. The OAuth proxy path that decrypts the passthrough cookie now also checks `oauthState` against the inner state when present. --- <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-04-15 22:46:18 -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#25219