Skip to content

fix(oauth): Relay upstream authorization errors to the MCP client - #2330

Merged
dcramer merged 3 commits into
mainfrom
fix/oauth-callback-relay-upstream-errors
Nov 19, 2026
Merged

dcramer merged 3 commits into
mainfrom
fix/oauth-callback-relay-upstream-errors

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

When the upstream authorization server returns an error to /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_uri with the client's original state and RFC 9207 iss, the same way /oauth/authorize already 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-code branch moved with it, so it is also behind those checks now.

Error code mapping. access_denied and temporarily_unavailable pass through, and server_error stays server_error. Every other upstream code, including invalid_request, invalid_scope, unauthorized_client, and unknown codes, becomes server_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_unavailable passes through because it tells the client that a retry may work.

Description. Each code gets a fixed error_description. The upstream error_description is never sent to the client. It is still recorded in the existing log context.

Logging is unchanged: the same [oauth] Upstream authorization callback error message goes to logWarn for user failures and to logIssue for system failures, based on getOAuthCallbackFailureDetails. 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 to server_error? I chose the narrower set for the reason above.

via @dcramer.

--

View Session [Sentry]

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>
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 19, 2026 10:36pm UTC
sentry-local Ready Ready Preview Nov 19, 2026 10:36pm UTC

Request Review

@dcramer
dcramer marked this pull request as ready for review November 19, 2026 22:23
@dcramer
dcramer requested a review from a team as a code owner November 19, 2026 22:24
@sentry-junior
sentry-junior Bot requested a review from dcramer November 19, 2026 22:24
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 19, 2026

@dcramer dcramer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@dcramer
dcramer merged commit aae9b4b into main Nov 19, 2026
28 checks passed
@dcramer
dcramer deleted the fix/oauth-callback-relay-upstream-errors branch November 19, 2026 23:22

This branch was successfully deployed

2 active deployments
Preview – sentry-local — 88ef3a22 Deployed Nov 19, 2026 by vercel[bot]
Preview – cli — 88ef3a22 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant