fix(runtime): validate redirect_uri on OAuth /authorize requests - #5122
Merged
Merged
Conversation
The createOAuthHandlers() authorization-server proxy already defines isValidRedirectUri() (https/localhost/custom-scheme only) and applies it during dynamic client registration, but handleAuthorize() never called it on the actual /authorize request — it only checked that redirect_uri was present. A crafted redirect_uri (e.g. a plain http:// URL to an attacker-controlled host) would be accepted, stored in the stateless pending-auth state, and later used to redirect the user's browser with the authorization code attached after the upstream OAuth exchange completes.
decocms Bot
pushed a commit
that referenced
this pull request
Jul 23, 2026
PR: #5122 fix(runtime): validate redirect_uri on OAuth /authorize requests Bump type: patch - @decocms/runtime (packages/runtime/package.json): 2.3.3 -> 2.3.4 Deploy-Scope: both
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.
Source: bug found while auditing
packages/runtime/src/oauth.tsfor missing validation on untrusted input (this tick's runtime-utilities focus area).Why a maintainer wants this:
createOAuthHandlers()implements a stateless OAuth 2.1 authorization-server proxy for MCP servers. It already definesisValidRedirectUri()(only allowshttps:,localhost/127.0.0.1, or a non-http custom scheme) and calls it during dynamic client registration (RFC 7591), buthandleAuthorize()— the actual/authorizeendpoint — never called it; it only checked thatredirect_uriwas non-empty. That means any client can pointredirect_uriat an arbitraryhttp://URL, which the server happily stores in its stateless encodedstateparam and later redirects the user's browser to (with the OAuth authorizationcodeattached) once the upstream provider completes the exchange — a classic OAuth open-redirect / code-leak vector (RFC 6749 §10.6).Failure scenario:
GET /authorize?response_type=code&redirect_uri=http://attacker.example.com/callbackwas accepted and, after the user approved access upstream, the flow redirected tohttp://attacker.example.com/callback?code=..., handing the attacker a valid authorization code exchangeable for an access token. The fix applies the existingisValidRedirectUri()check tohandleAuthorize(), returning400 invalid_requestfor a rejected URI, matching the check already enforced for client registration.Regression test:
packages/runtime/src/oauth.test.ts— newdescribe("OAuth /authorize handler")block asserts a plain-http://external redirect_uri is rejected with 400, and a validhttps://redirect_uri still proceeds to the upstream authorization redirect (302).Reviewer command:
bun test packages/runtime/src/oauth.test.tsChecks run locally:
bun run fmt(clean),cd packages/runtime && bunx tsc --noEmit(clean),bun test packages/runtime/src/oauth.test.ts(5→7 tests, all pass). Full CI validates the rest.Summary by cubic
Fixes an OAuth open-redirect/code leak by validating
redirect_urion/authorizeusingisValidRedirectUri(). Insecure or externalhttp://URIs now return 400 to prevent redirects to attacker-controlled sites.isValidRedirectUri()inhandleAuthorize()withinpackages/runtime/src/oauth.tsto allow onlyhttps,localhost/127.0.0.1, or custom schemes.packages/runtime/src/oauth.test.tsto rejecthttp://and allowhttps://redirect URIs.Written for commit 3fde859. Summary will update on new commits.