Exclude anonymous from additionalAuthorization#19335
Open
junhyeong9812 wants to merge 1 commit into
Open
Conversation
DefaultAuthorizationManagerFactory.anonymous() routed through the same createManager path as authenticated(), so additionalAuthorization was applied to it, contradicting the documented contract that it does not affect anonymous, permitAll, or denyAll. Return the anonymous manager directly so the contract holds. Closes spring-projectsgh-19334 Signed-off-by: junhyeong9812 <pickjog@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
DefaultAuthorizationManagerFactory.anonymous()applies the configuredadditionalAuthorization, contradicting the documented contract ofsetAdditionalAuthorization(...):Problem
anonymous()routes through the samecreateManager(AuthenticatedAuthorizationManager)path asauthenticated(),fullyAuthenticated(), andrememberMe(), which wraps the manager viawithAdditionalAuthorization(...):permitAll()anddenyAll()are inherited interface defaults and never go through this path, so they correctly stay unaffected.anonymous()does not.As a result, when an
additionalAuthorizationis configured (for example viaAuthorizationManagerFactories.multiFactor().requireFactors(...)), an anonymous request is denied because an anonymous user holds none of the required factors — even though the Javadoc promisesanonymousis unaffected.The existing test
anonymousWhenAdditionalAuthorizationThenNotInvokedonly calledfactory.anonymous()and assertedverifyNoInteractions(...). Because theallOfwrapping is lazy, that assertion passed at construction time even with the bug, so the regression was not caught.Fix
Have
anonymous()construct theAuthenticatedAuthorizationManagerdirectly (still setting thetrustResolver) and return it withoutwithAdditionalAuthorization, mirroring howpermitAll()/denyAll()stay unaffected.authenticated(),fullyAuthenticated(), andrememberMe()continue to applyadditionalAuthorization.The existing test is strengthened to actually
authorize(...)an anonymous authentication and assert it is granted, which fails on the previous code.Note on impact
This is a behavior change in the documented direction: an endpoint guarded only by
anonymous()will now allow anonymous principals even when a configuredadditionalAuthorization(e.g. an MFA/IP/tenant gate) would fail. This matches the documented contract. Callers that intentionally want both conditions should compose them explicitly, e.g.allOf(factory.anonymous(), extraCondition).anonymous()still denies authenticated users, so anonymous-only endpoints do not become open to logged-in users.Closes gh-19334