[PR #4991] [MERGED] fix(oauth-proxy): should skip state check for oauth proxy #13945

Closed
opened 2026-04-13 09:13:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4991
Author: @Bekacru
Created: 9/30/2025
Status: Merged
Merged: 9/30/2025
Merged by: @Bekacru

Base: canaryHead: fix/oauth-proxy-state


📝 Commits (4)

  • 57a9bbc fix(oauth-proxy): should skip state check for oauth proxy
  • fd60e04 only run on callback
  • d93b864 chore: fix ci
  • 72d1011 chore: fix ci

📊 Changes

5 files changed (+110 additions, -27 deletions)

View changed files

📝 docs/content/docs/plugins/oauth-proxy.mdx (+3 -1)
📝 packages/better-auth/src/init.ts (+6 -0)
📝 packages/better-auth/src/oauth2/state.ts (+10 -1)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+36 -4)
📝 packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts (+55 -21)

📄 Description

Summary by cubic

Fixes state_mismatch errors in OAuth Proxy flows by skipping the state cookie check only when proxying, while keeping strict state validation on same-origin flows. Adds safeguards to avoid proxying when not needed.

  • Bug Fixes
    • Added oauthConfig.skipStateCookieCheck and used it in parseState for proxied flows.
    • Introduced checkSkipProxy: do not proxy when productionURL equals baseURL or when x-skip-oauth-proxy is set.
    • Rewrite callbackURL only when proxying.
    • Updated docs with a warning about the security trade-off (dev/staging only).
    • Added tests for proxy redirect, same-origin behavior, and state enforcement without proxy.

🔄 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/4991 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 9/30/2025 **Status:** ✅ Merged **Merged:** 9/30/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/oauth-proxy-state` --- ### 📝 Commits (4) - [`57a9bbc`](https://github.com/better-auth/better-auth/commit/57a9bbc26115d4365e12a81a00694936e0a12fe6) fix(oauth-proxy): should skip state check for oauth proxy - [`fd60e04`](https://github.com/better-auth/better-auth/commit/fd60e042acca388a991d9a95af992b1bd7c09a9b) only run on callback - [`d93b864`](https://github.com/better-auth/better-auth/commit/d93b864d3cbea4b57a6d31381b38dc2f75fbef9f) chore: fix ci - [`72d1011`](https://github.com/better-auth/better-auth/commit/72d10113d6b714f22ce725c400f3a0e40887091e) chore: fix ci ### 📊 Changes **5 files changed** (+110 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/oauth-proxy.mdx` (+3 -1) 📝 `packages/better-auth/src/init.ts` (+6 -0) 📝 `packages/better-auth/src/oauth2/state.ts` (+10 -1) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+36 -4) 📝 `packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts` (+55 -21) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes state_mismatch errors in OAuth Proxy flows by skipping the state cookie check only when proxying, while keeping strict state validation on same-origin flows. Adds safeguards to avoid proxying when not needed. - **Bug Fixes** - Added oauthConfig.skipStateCookieCheck and used it in parseState for proxied flows. - Introduced checkSkipProxy: do not proxy when productionURL equals baseURL or when x-skip-oauth-proxy is set. - Rewrite callbackURL only when proxying. - Updated docs with a warning about the security trade-off (dev/staging only). - Added tests for proxy redirect, same-origin behavior, and state enforcement without proxy. <!-- 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-04-13 09:13:53 -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#13945