Repository navigation
Conversation
MCP clients register through Dynamic Client Registration on every connection, so each reconnect creates another client and the per-IP registration rate limit is shared by everyone connecting from the same platform. Client ID Metadata Documents (draft-ietf-oauth-client-id-metadata-document-02, adopted by the MCP authorization spec) let a client use an HTTPS URL as its client_id instead, and the server reads the client's metadata from that URL. Behind GOTRUE_OAUTH_SERVER_ALLOW_CLIENT_ID_METADATA_DOCUMENTS (off by default), with an optional host allow list in GOTRUE_OAUTH_SERVER_CLIENT_ID_METADATA_DOCUMENT_ALLOWED_HOSTS: - /oauth/authorize accepts a URL client_id. The document is fetched, validated and used to create or update a single client per URL (registration_type metadata_document), so consents and grants stay under one app. - Fetching follows the spec: https only, no redirects, 5 KB limit, 5 s timeout, JSON content type, client_id must match the URL, no client_secret and only token_endpoint_auth_method "none". Connections to special-use IP addresses (RFC 6890) are refused on the dialed address, so DNS rebinding can't bypass the check. - Valid documents are cached following Cache-Control (default 5 min, max 24 h); errors and invalid documents are never cached. - /oauth/token accepts the URL client_id for clients created this way. - ID token aud/client_id and the access token client_id claim use the URL, the identifier the client knows itself by. - Authorization details return client_id_url so consent screens can show its host, and the server metadata advertises client_id_metadata_document_supported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0187GfsUpzmeh8pDYi3eBwEq
netip reports fec0::/10 (site-local, RFC 3879) and ::/96 (IPv4-compatible, RFC 4291) addresses as global unicast, so the client metadata document fetcher could connect to them. Add both ranges to the special-use list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0187GfsUpzmeh8pDYi3eBwEq
This was referenced Nov 23, 2026
This branch has not been deployed
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.
What
Closes #2850.
Adds support for Client ID Metadata Documents (draft-02), which the MCP authorization spec uses so clients don't need to register. The client uses an HTTPS URL as its
client_id, and the server reads the client's metadata from that URL.Today MCP clients go through Dynamic Client Registration on every connection, so:
oauth_clientsrow and users see many near-identical apps;With this change, one URL maps to one client, so consents and grants stay under a single app.
How it works
Off by default:
/oauth/authorizeaccepts a URLclient_id. The document is fetched and validated, and a client withregistration_type = metadata_documentis created or updated from it (name, URIs, redirect URIs, grant types). Theredirect_urimust exactly match one in the document. Errors are returned as JSON (not redirected), since the redirect URI can't be trusted yet./oauth/tokenaccepts the URLclient_idfor clients created this way. The document is not fetched again there.aud/client_idand the access tokenclient_idclaim use the URL, the identifier the client knows itself by. Registered clients keep their UUID.GET /oauth/authorizations/{id}returnsclient.client_id_url, so the UI can show its host as the spec recommends (the metadata is self-asserted)./.well-known/oauth-authorization-serveradvertisesclient_id_metadata_document_supported: truewhen enabled.Spec requirements implemented
https, has a path, no user info, no dot segments (including percent-encoded ones), no fragment, no query.client_idmust match the URL with simple string comparison;client_secret/client_secret_expires_atare rejected;token_endpoint_auth_methodmust benone(shared secrets are forbidden by the spec andprivate_key_jwtisn't supported by this server);redirect_urisrequired and validated like DCR.application/jsonorapplication/*+json.Cache-Control(max-age,no-store,no-cache), default 5 minutes, at most 24 hours, bounded to 1000 entries. Errors and invalid documents are never cached.Migrations
20261031100000: addsmetadata_documenttooauth_registration_type.20261031100001: addsoauth_clients.client_id_url(≤ 2048 chars) with a unique index on active rows.openapi.yamland the generated admin client are updated (registration_typeenum,client_id_url).Not included / open questions
none).private_key_jwtwithjwks/jwks_uricould come later./oauth/authorizeis unauthenticated, so each distinct document URL served by a host can create a client row. The flag is off by default and the host allow list limits this; cleaning up metadata-document clients with no consents or sessions could be a follow-up.metadata_documentclient are overwritten the next time the document is fetched.Tests
internal/api/oauthserver/client_metadata_test.go: URL validation, special-use address detection,Cache-Controlhandling, fetcher against a TLS test server (caching, expiry, no-store, errors not cached, redirects not followed, every invalid document case), the default client refusing loopback, authorize creating a single client per URL and applying document changes, rejected documents, allow list, flag disabled,FindClientByClientID, and code exchange + refresh issuing the URL asclient_id.internal/api/oauth_client_id_metadata_test.go: discovery flag and/oauth/tokenclient authentication with a URLclient_idthrough the router.internal/tokens: ID tokenaud/client_iduse the client identifier.go test ./internal/api/oauthserver/ ./internal/models/ ./internal/tokens/ ./internal/conf/ ./internal/api/pass locally against Postgres 16, except tests that need outbound network/DNS, which fail the same way onmasterin my environment.🤖 Generated with Claude Code
https://claude.ai/code/session_0187GfsUpzmeh8pDYi3eBwEq