Skip to content

Add allowed scopes validation for DCR endpoints#19040

Open
addcontent wants to merge 1 commit intospring-projects:mainfrom
addcontent:dcr-scope-validation
Open

Add allowed scopes validation for DCR endpoints#19040
addcontent wants to merge 1 commit intospring-projects:mainfrom
addcontent:dcr-scope-validation

Conversation

@addcontent
Copy link
Copy Markdown

Summary

Add allowedScopes configuration to both OAuth2 and OIDC Dynamic Client Registration endpoints, along with documentation recommending its use.

Currently, DCR accepts any scope string verbatim during client registration. This PR adds a built-in mechanism to restrict which scopes are permitted, complementing the existing setRegisteredClientConverter() extension point with a simpler configuration option.

This was discussed in GHSA-wrvg-67fj-c87r, where @jgrandja agreed on adding documentation and considering a security enhancement.

Changes

  • Add setAllowedScopes(Set<String>) to OidcClientRegistrationAuthenticationProvider and OAuth2ClientRegistrationAuthenticationProvider
  • Add allowedScopes(String...) fluent API to both endpoint configurers
  • Add "Customizing Scope Validation" documentation section to both DCR endpoint pages in protocol-endpoints.adoc
  • Add tests for scope validation, backward compatibility, and null safety

Behavior

  • When allowedScopes is configured, registration requests with scopes outside the set are rejected with invalid_scope
  • When not configured (default), any scope is accepted — existing behavior is unchanged
  • Follows the same configurer-to-provider wiring pattern as openRegistrationAllowed

Signed-off-by: addcontent addcontent08@gmail.com

Add allowedScopes configuration to both OAuth2 and OIDC Dynamic Client
Registration endpoints. When configured, registration requests containing
scopes not in the allowed set are rejected with an invalid_scope error.

This addresses the scenario where DCR accepts arbitrary scope strings
verbatim, which could result in dynamically registered clients obtaining
tokens with unintended privilege scopes.

Changes:
- Add setAllowedScopes(Set<String>) to both authentication providers
- Add allowedScopes(String...) to both endpoint configurers
- Add documentation with security considerations for DCR scope validation
- Add tests for scope validation, backward compatibility, and null safety

Signed-off-by: addcontent <addcontent08@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants