The vulnerability is a Server-Side Request Forgery (SSRF) within the mcp-client-security library, specifically in the Dynamic Client Registration (DCR) feature. The root cause is the lack of input validation on URLs received from a potentially untrusted Model Context Protocol (MCP) server.
When DCR is enabled (spring.ai.mcp.client.authorization.dynamic-client-registration.enabled=true), the application attempts to dynamically register itself as an OAuth2 client. This process involves several steps where URLs are fetched and used:
-
Metadata Discovery: The McpMetadataDiscoveryService.getProtectedResourceMetadata function is called with a URL to fetch protected resource metadata. Before the patch, this URL was not validated, allowing an attacker to point it to an internal service.
-
Client Registration: The DynamicClientRegistrationService.register function is used to perform the registration. It takes an authorization server URL, discovers a registration endpoint from it, and then sends the registration request. Both the initial authorization server URL and the discovered endpoint were used without validation.
-
Client Configuration: The DefaultMcpOAuth2ClientManager.registerMcpClient method creates and stores a ClientRegistration object. This object contains several URLs for the OAuth2 flow (e.g., token endpoint, authorization endpoint, JWKS URI) that are extracted from the server's response. These URLs were not validated, meaning a compromised or malicious MCP server could configure the client to send requests to internal endpoints.
The patch addresses this by introducing a UrlValidator component that is used across these services to enforce that all externally-provided URLs conform to a security policy (e.g., requiring HTTPS and not pointing to internal or loopback addresses unless explicitly configured for development). By validating all URLs before they are used in HTTP requests, the patch effectively mitigates the SSRF vulnerability.