Add CIMD support for dynamic OAuth client metadata resolution#56
Merged
Conversation
…support CIMD client IDs
Resolves the two ChatGPT MCP connector warnings ("DCR unavailable" and
"CIMD unavailable") and the 500 returned for GET /connect/register.
- Protected-resource metadata (/.well-known/oauth-protected-resource[/**])
now advertises registration_endpoint (derived from AuthorizationServerSettings,
not hardcoded) and client_registration_types_supported: ["automatic"], so
ChatGPT auto-populates the Registration URL and enables the CIMD path.
- GlobalExceptionHandler maps HttpRequestMethodNotSupportedException to 405
instead of falling through to the generic 500 handler.
- Add CimdRegisteredClientRepository (primary, wrapping the JDBC repo): when a
client_id is an https URL it fetches the CIMD document, validates it, and
builds an ephemeral public PKCE-required RegisteredClient. Includes SSRF
protection (https-only, rejects loopback/private/link-local/multicast hosts)
and a dedicated RestClient with 3s connect / 5s read timeouts. Non-URL client
IDs delegate to JDBC, so existing GPT/MCP/DCR clients keep working.
- Tests: CimdRegisteredClientIT (CIMD authorize flow + JDBC delegation) and new
assertions in DynamicClientRegistrationIT for the metadata fields and 405.
https://claude.ai/code/session_017sx38pQgKSu1wvQX46nykP
Qodana for JVM3 new problems were found
View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2025.3.2
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
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.
Summary
Implements Client ID Metadata Document (CIMD) support in the authorization server, enabling clients like ChatGPT to present a metadata document URL as their
client_idinstead of pre-registering. The server fetches and validates these documents on-demand, creating ephemeral registered clients for the authorization flow.Key Changes
New
CimdRegisteredClientRepository: Wraps the JDBC repository to intercept HTTPS URL client IDs, fetch their metadata documents, and build ephemeralRegisteredClientinstances. Non-URL client IDs (bootstrapped clients, DCR-registered clients) delegate to JDBC as before.SSRF Protection: Validates CIMD URLs to ensure they use HTTPS and resolve only to public IP addresses (rejecting loopback, link-local, site-local, multicast, and any-local addresses).
Ephemeral Client Caching: Stores resolved CIMD clients in a
ConcurrentHashMapkeyed by SHA-256 hash of the client_id URL, allowing the token endpoint to reload clients without database persistence.Dedicated CIMD RestClient: Configures a
RestClientbean with tight timeouts (3s connect, 5s read) to prevent slow or hostile metadata URLs from stalling the authorization flow.Protected Resource Metadata Updates: Advertises the DCR endpoint and CIMD support (
client_registration_types_supported: ["automatic"]) in the OAuth protected resource metadata endpoint, enabling ChatGPT to discover these capabilities.HTTP Method Validation: Added exception handler for
HttpRequestMethodNotSupportedExceptionto return 405 (Method Not Allowed) instead of 500 for unsupported methods like GET on the POST-only DCR endpoint.Comprehensive Integration Tests: New
CimdRegisteredClientITverifies the full CIMD flow with mocked metadata document fetches, including redirect URI validation and fallback to JDBC for non-URL client IDs.Implementation Details
requireProofKey=true), no client authentication (NONE), and default token TTLs (1h access, 30d refresh).authorization_codeandrefresh_tokenif omitted from the metadata document.nullso Spring Security surfaces standard OAuth errors rather than 500s.https://claude.ai/code/session_017sx38pQgKSu1wvQX46nykP