Repository navigation
feat(mcp): accept Client ID Metadata Documents (00511) - #2274
Conversation
PR 5 of MCP over OAuth (ansvisor#2141), stacked on feature/mcp-oauth-consent. Still behind MCP_OAUTH_ENABLED. An app can name itself by an https URL serving a JSON document about it, instead of registering (MCP authorization spec 2025-11-25, "SHOULD"; 2026-07-28 deprecates dynamic registration in its favour). Claude and ChatGPT use one when the server advertises it, Claude Code always has one, and Anthropic recommends it over registration for directory traffic: one client per app, not one per connection. - The authorization server metadata says client_id_metadata_document_ supported, beside "none" among the token endpoint auth methods. - At /api/oauth/authorize, a client id that is a URL (https, a path, no query, fragment, credentials or dot segments) names its document. It is fetched safely (safe-fetch.ts: every address the host resolves to must be public, checked in the connection's own lookup; no redirects; 5 s; 10 KB; JSON only), checked (client_id equal to the URL exactly, redirect URIs as for registration, a public client, code with authorization_code and refresh_token only) and kept as a 'cimd' client for as long as its Cache-Control allows, five minutes to a day. One that can't be fetched or doesn't check out ends on Ansvisor's page. - The consent page names such an app by its URL's host (Claude for claude.ai), not by the name the document gives itself. - 00511: oauth_clients kind 'cimd', metadata_fetched_at and metadata_expires_at; a cimd client must be https, public and cached. Part of ansvisor#2141. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Rebuild supabase/schema.sql with main's migrations and 00511. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
left a comment
There was a problem hiding this comment.
SSRF: checkFetchUrl/isClientIdUrl accept an IP-literal host (https://10.0.0.1/x, https://169.254.169.254/x, https://[fd00::1]/x), and Node skips the custom lookup for IP hosts, so publicOnlyLookup's private-range check never runs; anyone can make the server GET internal addresses via /api/oauth/authorize?client_id=. Please reject hosts where net.isIP(hostname) is non-zero (or check them against the blocklist), and make the 5 s limit an overall timeout (AbortSignal.timeout), not the socket idle one.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
… 5 s A client ID URL with an IP host (https://10.0.0.1/x, https://169.254.169.254/x, https://[fd00::1]/x) connects without a DNS lookup, so publicOnlyLookup's private-range check never ran. Both isClientIdUrl and checkFetchUrl now refuse any IP host; the URL parser has already normalised 2130706433 and 0x7f.1. The 5 s limit was the socket's idle timeout, which a server sending a byte at a time keeps resetting. It is now one deadline for the whole request (AbortSignal.timeout), and a response cut off part way fails instead of resolving with a partial body. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
|
@gkhngyk thanks, both fixed in 2a36936:
Generated by Claude Code |
PR 7 of the MCP over OAuth plan (#2141). Merge after #2274 and after 00510 and 00511 are applied in production. - App sign-in is on unless MCP_OAUTH_ENABLED=false (the kill switch; 0, off and no too). It still needs an https issuer, so a self-hosted install on plain http stays off. - GET /.well-known/openai-apps-challenge serves OPENAI_APPS_CHALLENGE as text/plain, no-store, trimmed; 404 while unset. - The new key's Claude Desktop line says Claude can sign in instead. - Tool descriptions, the role refusal and get_site_audit_quota's error no longer assume an API key; the MCP coach skill likewise. - Gemini CLI: --scope user, so the key isn't written into the project's .gemini/settings.json; the docs keep $ANSVISOR_TOKEN a reference and say it writes url with type http, and how Gemini CLI can sign in. - Help (approved, regenerated), a what's-new entry (not approved), and docs: the MCP guide's app sign-in section, authentication, env vars. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Summary
PR 5 of the MCP over OAuth plan (#2141). Stacked on #2272 (the consent page), which is on
main: merge #2272 first. Until then this diff also shows #2272's commit. It is still behindMCP_OAUTH_ENABLED.What changes: an app can now name itself by an https URL serving a JSON document about it, instead of registering first. These are Client ID Metadata Documents (CIMD).
https://claude.ai/oauth/claude-code-client-metadata).What's built
client_id_metadata_document_supported: true, next to"none"intoken_endpoint_auth_methods_supported. Claude needs both before it uses CIMD.isClientIdUrl): https, a path, and no query, fragment, credentials, other port or./..segments. Anything else is a registered client id.web/src/lib/mcp-oauth/safe-fetch.ts, the guards of the API server'ssafe-fetch.jsported to the web for JSON):web/src/lib/mcp-oauth/cimd.ts):client_idmust equal the URL exactly; even a trailing slash is refused;redirect_urisfollow the same rules as registration (1 to 5; https or loopback; no custom schemes);token_endpoint_auth_methodabsent ornone);grant_typesmay only beauthorization_codeandrefresh_token, andresponse_typesonlycode;cimdclient, by its URL, for as long as itsCache-Controlallows, clamped to between 5 minutes and a day (an hour when it says nothing), then fetched again. A document that can't be fetched or doesn't check out leaves no client, and the request ends on Ansvisor's "unknown app" page./api/oauth/authorize: a URL client id goes through this. The request's redirect URI must be one the document lists; loopback matches on any port, which Claude Code needs.Migration
00511_mcp_oauth_cimd.sqloauth_clients.kindmay now becimd.metadata_fetched_atandmetadata_expires_at.oauth_clients_cimd_check: acimdclient must be https, public (none, no secret) and cached.cimdrow without the cache columns, a confidentialcimdclient and an unknown kind.supabase/build-schema.shwas run, andschema.sqlis committed. There is nobrand_idand no new function.Tests (
web/src/lib/mcp-oauth/cimd.test.ts, 52 tests)client_id, an http or custom-scheme redirect, no redirects,private_key_jwt,client_credentials,token, not an object);169.254.169.254, CGNAT,::1, v4-mapped loopback, ULA, link-local v6); the lookup refuses a name with any private address;/api/oauth/authorizewith Claude Code's URL andlocalhost:3118, a redirect URI the document doesn't list (Ansvisor's page), and a document that can't be fetched (unknown_client);The OAuth suites from #2262 and #2272 still pass unchanged.
No Help or docs change: nothing is switched on. Help and docs come with PR 7.
Related issue
Part of #2141
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd web && npx vitest run src/lib/mcp-oauth/cimd.test.ts.MCP_OAUTH_ENABLED=trueand 00510 and 00511 applied, open `/api/oauth/authorize?response_type=code&client_id=''https://claude.ai/oauth/claude-code-client-metadata&redirect_uri=http://localhost:3118/callback&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256':''oauth_clientshas acimdrow for that URL withmetadata_expires_atset.claude mcp add --transport http ansvisor <dev URL>/api/mcp, then/mcpto sign in: Claude Code uses its CIMD instead of registering.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)help/(or no user-visible change) — see help/README.md: nothing is switched on; Help comes with PR 7Checks run:
yarn buildpasses (with CI's placeholder env).upstream/main):src/components/oauth,src/lib/mcp-oauth,src/app/api/oauth,src/app/api/mcp,src/lib/mcp, bothmcp-authtests,embed-hints,subscription-guard-coverageandbrand-access-functions: 72 files, 694 tests passed;brand-access-policies,-schema,-account-tables,demo/coverage): 4 files, 74 tests passed.main(f947d77, with the Slack and HubSpot migrations):schema.sqlwas rebuilt, its only conflict. The branch's test files, Help,yarn typecheckand the 4 server migration tests pass again.Generated by Claude Code