Repository navigation
fix(oauth): Relay upstream authorization errors to the MCP client - #2330
Merged
Merged
Conversation
When the upstream authorization server returned an `error` to the callback (for example the user denied consent), the callback rendered a local HTML page. The MCP client never received an authorization response, so it could not tell the user what happened. The callback now validates the signed state, the client approval cookie, and that the client's redirect URI is registered before it looks at an upstream error. It then redirects to that redirect URI per RFC 6749 §4.1.2.1 with the client's original `state`, RFC 9207 `iss`, and a fixed `error_description`. `access_denied` and `temporarily_unavailable` pass through; every other code becomes `server_error`, since those describe this server's upstream request rather than the client's request. If any validation fails, the callback still returns a local error and never redirects. Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
approved these changes
Nov 19, 2026
dcramer
left a comment
Member
There was a problem hiding this comment.
I'm slightly paranoid when there's a macro change like this, but if the RFC says it's correct and something breaks, we'll fix it. but until then we should try to follow RFC when possible
Looks like there's conflicts that we need to fix up before this can be merged in though
…lay-upstream-errors # Conflicts: # packages/mcp-cloudflare/src/server/oauth/routes/authorize.ts
Main now type-checks indexed access strictly, so guard the split state the same way the existing tampered-state test does.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the upstream authorization server returns an
errorto/oauth/callback(for example, the user denies consent), the callback renders its own "Authentication Failed" HTML page. The MCP client never gets an authorization response, so it hangs waiting for its redirect or has nothing useful to show.The callback now follows RFC 6749 §4.1.2.1. It redirects the error to the client's
redirect_uriwith the client's originalstateand RFC 9207iss, the same way/oauth/authorizealready handles deny and validation errors.This changes behaviour for every MCP client. A denied or failed upstream authorization now reaches the client as an error redirect, not as an HTML page in the browser. This is the RFC-correct behaviour.
Order of checks. The upstream-error branch used to run before the approved-client cookie check and before the registered-redirect-URI check. It now runs only after the signed state, the approval cookie, and the registered redirect URI all pass. If any of them fails, the callback returns the same local error as before and never redirects, so an error never goes to an unvalidated URI. The missing-
codebranch moved with it, so it is also behind those checks now.Error code mapping.
access_deniedandtemporarily_unavailablepass through, andserver_errorstaysserver_error. Every other upstream code, includinginvalid_request,invalid_scope,unauthorized_client, and unknown codes, becomesserver_error. Those codes describe this server's own upstream request (scopes, client credentials, response type), not the MCP client's request. Relaying them would tell the client its request was wrong when the problem is on our side.temporarily_unavailablepasses through because it tells the client that a retry may work.Description. Each code gets a fixed
error_description. The upstreamerror_descriptionis never sent to the client. It is still recorded in the existing log context.Logging is unchanged: the same
[oauth] Upstream authorization callback errormessage goes tologWarnfor user failures and tologIssuefor system failures, based ongetOAuthCallbackFailureDetails. This path emitted no metrics before, and it still emits none.Open decision for reviewers: should we pass through more standard codes (for example
invalid_scope) instead of mapping them toserver_error? I chose the narrower set for the reason above.via @dcramer.
--
View Session [Sentry]