Authorization Server consent fails on client with no registered scopes
Describe the bug
If a registered client supporting the authorization_code has no scopes, and requires authorization consent.
When a client makes an authorization request decision, they see a consent screen with no scopes displayed (see screenshot).
If the user clicks "submit consent", an oauth2 error redirect happens, because it is expected that there is at least one scope consented to (source)
Expected behavior
I see three options:
- Disallow the "require consent + 0 scope" combination for clients
- Allow the combination but skip the consent screen
- Allow the combination, present the screen and allow the user to click "submit consent"
Screenshot
I'd like to work on this issue.
For info, my current workaround, to skip the screen if there are no registered scopes:
/**
* Customizer for {@link OAuth2AuthorizationCodeRequestAuthenticationProvider}, that
* removes the need for consent when a client was registered with 0 scopes. Otherwise, the
* user cannot get past the consent screen with no scopes present. It is lifted from
* {@link OAuth2AuthorizationCodeRequestAuthenticationProvider}'s
* {@code isAuthorizationConsentRequired}, with a special case for "no scopes registered".
*
* @see <a href=
* "https://github.com/spring-projects/spring-security/issues/18565">spring-security/issues/18565</a>
* @author Daniel Garnier-Moiroux
*/
class McpNoScopeClientConsentNotRequired implements Predicate<OAuth2AuthorizationCodeRequestAuthenticationContext> {
@Override
public boolean test(OAuth2AuthorizationCodeRequestAuthenticationContext authenticationContext) {
if (!authenticationContext.getRegisteredClient().getClientSettings().isRequireAuthorizationConsent()) {
return false;
}
if (authenticationContext.getAuthorizationRequest().getScopes().isEmpty()) {
return false;
}
// 'openid' scope does not require consent
if (authenticationContext.getAuthorizationRequest().getScopes().contains(OidcScopes.OPENID)
&& authenticationContext.getAuthorizationRequest().getScopes().size() == 1) {
return false;
}
if (authenticationContext.getAuthorizationConsent() != null && authenticationContext.getAuthorizationConsent()
.getScopes()
.containsAll(authenticationContext.getAuthorizationRequest().getScopes())) {
return false;
}
return true;
}
public static ObjectPostProcessor<OAuth2AuthorizationCodeRequestAuthenticationProvider> postProcessor() {
return new ObjectPostProcessor<>() {
@Override
public <O extends OAuth2AuthorizationCodeRequestAuthenticationProvider> O postProcess(
O authenticationProvider) {
authenticationProvider.setAuthorizationConsentRequired(new McpNoScopeClientConsentNotRequired());
return authenticationProvider;
}
};
}
}
Then configure your auth server:
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
return http.oauth2AuthorizationServer(authServer -> {
authServer.addObjectPostProcessor(McpNoScopeClientConsentNotRequired.postProcessor());
// ... more authserver customizations
})
// ... more security config
.build();
}
@Kehrlann After reviewing this use case, I believe this is a misconfiguration.
Take this use case into account:
The client requests one or more individual claims using the claims parameter OR requests an authority, which is custom to the application.
Given this use case, the application would need to configure a custom consent page to display the claim(s) and/or custom authorities, as well, the client would need to be configured with requireAuthorizationConsent(true). Additionally, the application would need to configure OAuth2AuthorizationConsentAuthenticationProvider.setAuthorizationConsentCustomizer() to handle the submitted claims/authorities and ultimately populate OAuth2AuthorizationConsent.Builder.authority() with the authorized claim/authority.
I see three options:
- Disallow the "require consent + 0 scope" combination for clients
- Allow the combination but skip the consent screen
- Allow the combination, present the screen and allow the user to click "submit consent"
These options would not work as it would bypass the above use case.
Lastly, requireAuthorizationConsent(false) is the default setting so setting it to requireAuthorizationConsent(true) would likely require other configuration settings to ensure the consent process works as expected, hence why I believe your use case is a misconfiguration.
Does this make sense?
@jgrandja good point, I had not thought of things beyond requesting scopes.
I agree that if the default "require consent" is false, then this is not a problem. However, dynamic client registration sets require consent to true, both OIDC and OAuth2. Maybe we should set this to false, or set it to false when no scopes are registered?
@Kehrlann
dynamic client registration sets require consent to true
This makes sense to default to requireAuthorizationConsent(true) for dynamic registered clients and is recommended as per spec.
You could override the default with a custom converter delegation-based strategy. See this sample
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.