8000 feat: validate dynamic client registration by roerohan · Pull Request #96 · cloudflare/workers-oauth-provider · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@roerohan
Copy link
Contributor

This change introduces a new validateClientRegistration callback to the OAuthProvider options, enhancing the security of the dynamic client registration feature.

The Problem

Previously, when the clientRegistrationEndpoint was enabled, the library allowed any client to register without restriction. This posed a security risk, as it could allow malicious or unauthorized clients to be registered with the OAuth provider.

The Solution

To address this, I have added a new optional callback function, validateClientRegistration, to the OAuthProviderOptions. This function is executed before a new client is registered and allows developers to implement custom validation logic.

The callback receives the clientMetadata and the original request as arguments and should return a boolean value indicating whether the registration is allowed. If the function returns false, the registration is denied with a 403 Forbidden error.

I have also updated the README.md to:

  • Add a new "Security" section.
  • Document the importance of CSRF prevention using the state parameter.
  • Provide a detailed explanation and a code example for using the new validateClientRegistration callback to secure the dynamic client registration endpoint.

This change empowers developers to enforce their own policies on client registration, such as allowlisting specific domains for redirect URIs or requiring an authentication token for the registration request.

@changeset-bot
Copy link
changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: 34f421e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/workers-oauth-provider Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
pkg-pr-new bot commented Oct 21, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/workers-oauth-provider/@cloudflare/workers-oauth-provider@96

commit: 34f421e

@roerohan roerohan changed the title feat: dynamic client registration feat: validate dynamic client registration Oct 21, 2025
@whoiskatrin whoiskatrin requested a review from kentonv October 22, 2025 14:41
Copy link
Member
@kentonv kentonv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole point of DCR is to let arbitrary clients register with the service. An MCP server, for example, wants to allow any agent to use it, including agents the service owner hasn't heard of.

So what validation can they possibly do?

If you have a server that doesn't want to allow everyone to register, then you should turn of DCR, and instead issue client credentials to the specific clients that you want to allow, or implement an alternative registration mechanism that matches your business needs.

@roerohan
Copy link
Contributor Author

The whole point of DCR is to let arbitrary clients register with the service. An MCP server, for example, wants to allow any agent to use it, including agents the service owner hasn't heard of.

So what validation can they possibly do?

If you have a server that doesn't want to allow everyone to register, then you should turn of DCR, and instead issue client credentials to the specific clients that you want to allow, or implement an alternative registration mechanism that matches your business needs.

I see your point - I was under the assumption that DCR could still be useful for organizations that want to enable dynamic registration for clients within their own domain. For example, an internal MCP server might allow DCR for all clients hosted on the same domain, or maybe just for trusted internal tools and editors. In that kind of controlled environment, DCR could still make sense without opening it up to arbitrary external clients.

@kentonv
Copy link
Member
kentonv commented Oct 27, 2025

I could be convinced that "DCR with restrictions" makes sense for certain use cases, but I think we need to enumerate real-world use cases before we design a solution.

Meanwhile I've heard MCP is moving away from DCR so maybe this problem will go away soon anyawy.

@DeanMauro DeanMauro mentioned this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0