Title: DCR registration accepts redirect_uris with non-HTTPS / non-loopback / fragmented schemes · Issue #2629 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: DCR registration accepts redirect_uris with non-HTTPS / non-loopback / fragmented schemes · Issue #2629 · modelcontextprotocol/python-sdk
X Title: DCR registration accepts redirect_uris with non-HTTPS / non-loopback / fragmented schemes · Issue #2629 · modelcontextprotocol/python-sdk
Description: Summary The DCR handler (mcp.server.auth.handlers.register.RegistrationHandler.handle) does not validate the scheme of submitted redirect_uris. A client registered via DCR can supply javascript:, data:, vbscript:, file:, ftp:, or clearte...
Open Graph Description: Summary The DCR handler (mcp.server.auth.handlers.register.RegistrationHandler.handle) does not validate the scheme of submitted redirect_uris. A client registered via DCR can supply javascript:, d...
X Description: Summary The DCR handler (mcp.server.auth.handlers.register.RegistrationHandler.handle) does not validate the scheme of submitted redirect_uris. A client registered via DCR can supply javascript:, d...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2629
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DCR registration accepts redirect_uris with non-HTTPS / non-loopback / fragmented schemes","articleBody":"## Summary\n\nThe DCR handler (`mcp.server.auth.handlers.register.RegistrationHandler.handle`) does not validate the scheme of submitted `redirect_uris`. A client registered via DCR can supply `javascript:`, `data:`, `vbscript:`, `file:`, `ftp:`, or cleartext `http://` (non-loopback) values, and they pass through to the provider's `register_client`. The SDK already enforces an HTTPS-or-loopback policy on the Issuer URL (`routes.validate_issuer_url`); the same policy is missing for registered `redirect_uris`. RFC 9700 §4.1.1 and RFC 7591 §2 require it.\n\n## Reproduction\n\nThe underlying field, `mcp.shared.auth.OAuthClientMetadata.redirect_uris` (`src/mcp/shared/auth.py:40`), is typed `list[AnyUrl] | None`. Pydantic's `AnyUrl` accepts any well-formed URL with a scheme. Verified on `main` at `161834d4ae`:\n\n```python\nfrom pydantic import AnyUrl, BaseModel, Field\nfrom typing import List\n\nclass M(BaseModel):\n redirect_uris: List[AnyUrl] = Field(..., min_length=1)\n\nfor uri in [\n \"javascript:alert(1)\",\n \"data:text/html,\u003cscript\u003ealert(1)\u003c/script\u003e\",\n \"file:///etc/passwd\",\n \"vbscript:msgbox(1)\",\n \"ftp://attacker.example/cb\",\n \"http://attacker.example/cb\",\n \"https://example.com/cb#frag\",\n \"https://example.com/cb#\",\n]:\n M(redirect_uris=[uri]) # all accepted, no ValidationError\n```\n\nAgainst a running MCP server with the default DCR handler, `POST /register` with any of the above values returns 201 and stores the URI. After registration, `OAuthClientMetadata.validate_redirect_uri` does exact-equality match against the registered list, so the bad URI is accepted as the authorization callback target.\n\n## Existing parallel logic to mirror\n\n`src/mcp/server/auth/routes.py:24–42` (`validate_issuer_url`):\n\n```python\nif url.scheme != \"https\" and url.host not in (\"localhost\", \"127.0.0.1\", \"[::1]\"):\n raise ValueError(\"Issuer URL must be HTTPS\")\n\nif url.fragment:\n raise ValueError(\"Issuer URL must not have a fragment\")\n```\n\n## Related\n\n- #1446 (closed as `duplicate`, no cross-reference recorded) — raised the same concern in question form.\n- #1934 (open) — fixes RFC 8252 §7.3 loopback port matching at authorize-time. Adjacent surface but orthogonal; does not add scheme validation at register-time.\n- TypeScript SDK PR `modelcontextprotocol/typescript-sdk#1738` covers the same authorize-time loopback gap on the TS side.\n\n## Proposed fix\n\nAdd `validate_registered_redirect_uri(url: AnyUrl) -\u003e None` next to `validate_issuer_url`:\n\n- Reject schemes other than `https`, or `http` with host in `{\"localhost\", \"127.0.0.1\", \"[::1]\"}`.\n- Reject URIs with a fragment (including empty fragments, e.g. `https://example.com/cb#` — note: this is also a latent bug in `validate_issuer_url`'s current `if url.fragment:` check, which I have NOT touched here to keep scope tight).\n- Permit query strings (RFC 7591 §2 explicitly allows them).\n\nCall it once per URI in `RegistrationHandler.handle` immediately after `model_validate_json` succeeds. On failure return `400 invalid_redirect_uri` per RFC 7591 §3.2.2.\n\nPR with the patch + tests: #\u003cPR_NUM_HERE\u003e.\n\n## Notes on severity\n\nBrowsers no longer navigate `javascript:` / `data:` schemes received in `Location` headers, which neutralises those vectors for browser-mediated flows. The realistic exploitable residue is (a) cleartext-HTTP redirect_uris to attacker-controlled hosts, and (b) custom-scheme deep links on devices where the MCP client uses a system handler. Defense-in-depth, not a critical exploit chain — happy to be downgraded if maintainers see it differently.\n","author":{"url":"https://github.com/CrypticCortex","@type":"Person","name":"CrypticCortex"},"datePublished":"2026-05-18T11:56:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2629/python-sdk/issues/2629"}
| 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:6d096cdf-7361-168c-d166-a2a75c8b330e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C0B8:10077:4DEE93:6A7D89:6A591E5E |
| html-safe-nonce | 5822937836436d89646c9c5b7dbd4972e1c14b07ef86c5bb754898c9a60d4255 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEI4OjEwMDc3OjRERUU5Mzo2QTdEODk6NkE1OTFFNUUiLCJ2aXNpdG9yX2lkIjoiMTc4NDY1Nzg1MjEzODg1NjAzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 092cd0d10e07f9942043e587cb73515af15683df37e9092c25188d5b1d951b7e |
| hovercard-subject-tag | issue:4468871434 |
| 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/modelcontextprotocol/python-sdk/2629/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8479c176fe3008919b3cf8ab5ddf68eff66ec95f925b86a99e48037dddc82e43/modelcontextprotocol/python-sdk/issues/2629 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8479c176fe3008919b3cf8ab5ddf68eff66ec95f925b86a99e48037dddc82e43/modelcontextprotocol/python-sdk/issues/2629 |
| og:image:alt | Summary The DCR handler (mcp.server.auth.handlers.register.RegistrationHandler.handle) does not validate the scheme of submitted redirect_uris. A client registered via DCR can supply javascript:, d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CrypticCortex |
| hostname | github.com |
| expected-hostname | github.com |
| None | de7b53b927e5bfbf02672a5b2960bf82d1608d91c6d7888039c826ebf8d4ca76 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| 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 | 020f8e5d3a42ae1a22d3f297198ccfca124edd1d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width