spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

Authorization Server consent fails on client with no registered scopes

Open Kehrlann opened this issue 10 months ago • 7 comments

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

Image

Kehrlann avatar Jan 23 '26 17:01 Kehrlann

I'd like to work on this issue.

ryujungkyun avatar Jan 24 '26 12:01 ryujungkyun

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 avatar Jan 26 '26 15:01 Kehrlann

@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 avatar Feb 04 '26 11:02 jgrandja

@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 avatar Feb 04 '26 11:02 Kehrlann

@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

jgrandja avatar Feb 05 '26 17:02 jgrandja

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.

spring-projects-issues avatar Feb 19 '26 11:02 spring-projects-issues

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.

spring-projects-issues avatar Feb 26 '26 11:02 spring-projects-issues