feat(config): disable device_code grant by default #2068
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.
Overview
This PR introduces an opt-in switch for the OAuth 2.0 Device Authorization Grant (aka
device_code
) in Spring Authorization Server.By default the grant is disabled, bringing the framework in line with the “secure-by-default” principle discussed in [#1709](#1709).
Motivation
Most new deployments of the Authorization Server target browser-based or mobile clients and do not require this flow.
/oauth2/device_authorization
,/oauth2/device_verification
) increases the attack surface and the number of code paths that must be audited.What changed
AuthorizationServerSettings
deviceGrantEnabled
(defaultfalse
).deviceGrantEnabled(boolean)
– fluent opt-in.OAuth2DeviceAuthorizationEndpointConfigurer
andOAuth2DeviceVerificationEndpointConfigurer
now short-circuit theirinit()
/configure()
methods when the flag isfalse
. No filters or providers are registered.OAuth2AuthorizationServerConfigurer
skips Device Grant matchers unless the flag is enabled; avoids null request-matcher issues.device-grant-enabled
toConfigurationSettingNames.AuthorizationServer
.404
when the flag is left at its default value.Opting back in
Once enabled, behaviour is identical to previous versions; no further changes are required in client or resource owner flows.
Backward compatibility
No—deployments that actively use the Device Grant just need to flip one property. All other grants continue to function unchanged.
deviceGrantEnabled(true)
is configured the runtime behaviour is byte-for-byte equivalent to currentmain
.Test coverage
OAuth2DeviceCodeGrantTests
now run with the flag enabled.requestWhenDeviceAuthorizationEndpointDisabledThenNotFound
verifies that the endpoint is not exposed by default../gradlew check
).Upgrade notes
deviceGrantEnabled(true)
to yourAuthorizationServerSettings
bean (see snippet above).Related links
Checklist
./gradlew clean build
)Signed-off-by
) and follows Conventional Commit format*Signed-off-by: renechoi [[[email protected]]