Title: bug: OAuth2 authorize rejects redirect_uri that is not the first registered redirect_uris entry (Cursor MCP) · Issue #28910 · coder/coder · GitHub
Open Graph Title: bug: OAuth2 authorize rejects redirect_uri that is not the first registered redirect_uris entry (Cursor MCP) · Issue #28910 · coder/coder
X Title: bug: OAuth2 authorize rejects redirect_uri that is not the first registered redirect_uris entry (Cursor MCP) · Issue #28910 · coder/coder
Description: Current Behavior Cursor desktop can't complete OAuth2 against the remote MCP server (/api/experimental/mcp/http). After Dynamic Client Registration succeeds, GET /oauth2/authorize renders: 400 - Invalid Query Parameters Query param "redi...
Open Graph Description: Current Behavior Cursor desktop can't complete OAuth2 against the remote MCP server (/api/experimental/mcp/http). After Dynamic Client Registration succeeds, GET /oauth2/authorize renders: 400 - In...
X Description: Current Behavior Cursor desktop can't complete OAuth2 against the remote MCP server (/api/experimental/mcp/http). After Dynamic Client Registration succeeds, GET /oauth2/authorize renders: 400 ...
Opengraph URL: https://github.com/coder/coder/issues/28910
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: OAuth2 authorize rejects redirect_uri that is not the first registered redirect_uris entry (Cursor MCP)","articleBody":"### Current Behavior\n\nCursor desktop can't complete OAuth2 against the remote MCP server (`/api/experimental/mcp/http`). After Dynamic Client Registration succeeds, `GET /oauth2/authorize` renders:\n\n```\n400 - Invalid Query Parameters\nQuery param \"redirect_uri\" must exactly match cursor://anysphere.cursor-mcp/oauth/callback\n```\n\nCursor registers two redirect URIs in one DCR request, per their MCP docs:\n\n* `cursor://anysphere.cursor-mcp/oauth/callback`\n* `https://www.cursor.com/agents/mcp/oauth/callback`\n\nCoder stores both, then only ever validates against the first one.\n\n### Root cause\n\n`coderd/oauth2provider/registration.go` persists the full list but derives a single primary URL:\n\n```go\nCallbackURL: req.RedirectURIs[0], // Primary redirect URI\nRedirectUris: req.RedirectURIs,\n```\n\n`app.RedirectUris` is never read again. `ShowAuthorizePage`, `ProcessAuthorize` (`authorize.go`) and `Tokens` (`tokens.go`) all do:\n\n```go\ncallbackURL, err := url.Parse(app.CallbackURL)\n...\nparams, _, err := extractAuthorizeParams(r, callbackURL)\n```\n\nand `httpapi.QueryParamParser.RedirectURL` enforces `v.String() != base.String()` against that single URL.\n\nSo any RFC 7591 client that registers more than one `redirect_uris` entry and uses anything but index 0 is rejected. This affects Cursor today and will affect any client that registers a desktop deep link plus a web callback.\n\n### Expected Behavior\n\n`redirect_uri` on `/oauth2/authorize` and `/oauth2/token` is accepted if it exactly matches **any** entry in the app's registered `redirect_uris` (OAuth 2.1 exact-match, but against the whole allowlist). Apps created through the UI/API have an empty `redirect_uris`, so fall back to `callback_url` for them.\n\n### Steps to Reproduce\n\n1. Run Coder with `CODER_EXPERIMENTS=oauth2,mcp-server-http`.\n2. In Cursor, add an MCP server with URL `https://\u003cdeployment>/api/experimental/mcp/http` (or install the Coder Cursor plugin).\n3. Click Connect. Browser opens the Coder authorize page and renders the 400 above.\n\n### Proposed fix\n\nIn `authorize.go` and `tokens.go`, replace the single `callbackURL` with a lookup that matches the presented `redirect_uri` against `app.RedirectUris` (falling back to `app.CallbackURL` when the list is empty), and pass the matched URL into `extractAuthorizeParams` / `extractTokenRequest` so the existing exact-match check still holds. When `redirect_uri` is omitted, keep the current behavior of defaulting to `callback_url`. Add a test in `authorize_test.go` and `tokens_test.go` that registers two URIs and authorizes with the second.\n\n### Environment\n\n* Coder version: [dev.coder.com](\u003chttp://dev.coder.com>) (main, `8b8c806`)\n* Cursor desktop, remote MCP with OAuth2 discovery\n\nRelated to #19581 (same Cursor callbacks, earlier failure at registration).\n","author":{"url":"https://github.com/matifali","@type":"Person","name":"matifali"},"datePublished":"2026-09-02T18:26:06Z","url":"https://github.com/coder/coder/issues/28910"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:92cece32-c6cd-91b0-2e90-ceb80fe8a102 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9306:11284C:541D9:6FF4C:6B015C5A |
| html-safe-nonce | 1cf09998a5ee4278b0c963fbe3166bf77eff7b66dca502a35f826546dd185748 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzA2OjExMjg0Qzo1NDFEOTo2RkY0Qzo2QjAxNUM1QSIsInZpc2l0b3JfaWQiOiIzMzMzNzgxMTM5MTAwODg0MDU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a7ef8d0aef4fb2a4367f6c2266b6ad7201008d3e55da7aca24cde51627f6161d |
| hovercard-subject-tag | issue:5327695404 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/28910/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a801f36aa2f4ea5675bc0fc48e2f9c15b05a238f6b13f122e9a31f190dbec87f/coder/coder/issues/28910 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a801f36aa2f4ea5675bc0fc48e2f9c15b05a238f6b13f122e9a31f190dbec87f/coder/coder/issues/28910 |
| og:image:alt | Current Behavior Cursor desktop can't complete OAuth2 against the remote MCP server (/api/experimental/mcp/http). After Dynamic Client Registration succeeds, GET /oauth2/authorize renders: 400 - In... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | matifali |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width