Harden MCP OAuth callback handling (#40691)

## Why

MCP servers can share an OAuth callback URL. Without a validated issuer or a
server-specific callback path, an authorization response could be associated
with the wrong server.

## What changed

- Use stable callbacks when authorization metadata advertises issuer-bound
  responses, and validate the returned issuer before exchanging the code.
- Retain server-specific callback IDs for providers without issuer support,
  including fallback to the global or default callback for legacy registered
  clients.
- Persist registered callback URLs for MCP servers and plugins, and insert the
  active listener port into portless loopback redirects.

## Testing

Add coverage for issuer validation, callback-mode discovery, registered and
legacy clients, plugin OAuth, CLI persistence, and loopback listener ports.

GitOrigin-RevId: 2878c92e237fc17fd3def0bd2e1cce3e104a3db8
This commit is contained in:
stevenlee-oai authored and copyberry committed 2026-08-25 20:26:23 +00:00
1 parent 32ce703a80
commit 9be8d6e1c3
28 files changed
+1096 -127

No files matched your search

@@ -205,6 +205,7 @@ async fn maybe_install_mcp_dependencies(
server_config.oauth_resource.as_deref(),
callback_port,
config.mcp_oauth_callback_url.as_deref(),
config.mcp_oauth_callback_url.as_deref(),
Arc::clone(&http_client),
)
.await;
@@ -224,6 +225,7 @@ async fn maybe_install_mcp_dependencies(
server_config.oauth_resource.as_deref(),
callback_port,
config.mcp_oauth_callback_url.as_deref(),
config.mcp_oauth_callback_url.as_deref(),
Arc::clone(&http_client),
)
.await
@@ -427,6 +429,7 @@ fn mcp_dependency_to_server_config(
.oauth_callback_port
.map(|callback_port| McpServerOAuthConfig {
client_id: None,
callback_url: None,
callback_port: Some(callback_port),
}),
oauth_resource: None,