[PR #6822] [MERGED] fix: don't set state query param if state is not provided #6903

Closed
opened 2026-03-13 13:16:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6822
Author: @paoloricciuti
Created: 12/17/2025
Status: Merged
Merged: 12/23/2025
Merged by: @himself65

Base: canaryHead: fix-mcp-auth-undefined-state


📝 Commits (2)

  • bc1deaf fix: don't set state query param if state is not provided
  • bef39ea fix: lint

📊 Changes

2 files changed (+52 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/mcp/authorize.ts (+6 -2)
📝 packages/better-auth/src/plugins/mcp/mcp.test.ts (+46 -0)

📄 Description

Right now the redirect always set the state query parameter regardless if state is passed or not...however this leads to state=undefined in the url which is not useful and was actually breaking opencode (I also have a PR to fix on their side https://github.com/sst/opencode/pull/5681 ).

Avoiding setting state is more correct so here's the PR to do that.


Summary by cubic

Prevented adding state=undefined to MCP OAuth redirect URLs by only setting state when it’s provided. This fixes broken redirects and matches expected OAuth behavior.

  • Bug Fixes
    • Conditionally set the state param in authorizeMCPOAuth.
    • Added a test to confirm redirects omit state when not supplied and still include the code.

Written for commit bef39ea716. Summary will update automatically on new commits.


🔄 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/6822 **Author:** [@paoloricciuti](https://github.com/paoloricciuti) **Created:** 12/17/2025 **Status:** ✅ Merged **Merged:** 12/23/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix-mcp-auth-undefined-state` --- ### 📝 Commits (2) - [`bc1deaf`](https://github.com/better-auth/better-auth/commit/bc1deaff18c22a7bf6f94ea18ba36c2ee7c4618c) fix: don't set state query param if state is not provided - [`bef39ea`](https://github.com/better-auth/better-auth/commit/bef39ea7165fbe6f19d1dcc84f24b781aea971fa) fix: lint ### 📊 Changes **2 files changed** (+52 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/mcp/authorize.ts` (+6 -2) 📝 `packages/better-auth/src/plugins/mcp/mcp.test.ts` (+46 -0) </details> ### 📄 Description Right now the redirect always set the `state` query parameter regardless if state is passed or not...however this leads to `state=undefined` in the url which is not useful and was actually breaking opencode (I also have a PR to fix on their side https://github.com/sst/opencode/pull/5681 ). Avoiding setting `state` is more correct so here's the PR to do that. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevented adding state=undefined to MCP OAuth redirect URLs by only setting state when it’s provided. This fixes broken redirects and matches expected OAuth behavior. - **Bug Fixes** - Conditionally set the state param in authorizeMCPOAuth. - Added a test to confirm redirects omit state when not supplied and still include the code. <sup>Written for commit bef39ea7165fbe6f19d1dcc84f24b781aea971fa. Summary will update automatically on new commits.</sup> <!-- 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 13:16:27 -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#6903