-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Methods annotated with @PostFilter are processed twice by PostFilterAuthorizationMethodInterceptor #15624
Comments
Hi @kse-music, thanks for the report. I believe this is a duplicate of #15608. Would you please wait for #15608 to be fixed and check if it fixes the problem? |
Hi @marcusdacoregio |
@RADickinson, thanks for this report. I had hoped to get a fix out in time for the release this morning; however it will need to wait until the next release. In the meantime, it is permissible to continue using |
Closed in 5c604b9 |
Thanks @jzheaux for fixing this issue. |
Bug description
Found in version: 5.8.13
Fix required in: 5.8.x (required to enable migration to Spring Security 6).
While migrating from
@EnableGlobalMethodSecurity(prePostEnabled = true)
to@EnableMethodSecurity
we have noticed themethods annotated with
@PostFilter
are processed twice by thePostFilterAuthorizationMethodInterceptor
.We use a custom
PermissionEvaluator
and customMethodSecurityExpressionHandler
to evaluatehasPermission
expressions used with various prePost security annotations, for example:
The implementation of the
PermissionEvaluator
andMethodSecurityExpressionHandler
is relatively operationallyexpensive and filtered objects are modified in some cases (from custom types) as well as removed from standard array /
collection / stream types (using the
DefaultMethodSecurityExpressionHandler
). Running the filter twice for eachoperation annotated with
@PostFilter
leads to application errors and also significantly reduces performance.We need this issue to be fixed in the 5.8.x version to enable us to complete migration steps towards upgrade to
Spring Security 6.
Sample
A minimal sample of the issue is provided in this repository.
Steps to reproduce
The sample repository contains sample code and configuration used to reproduce the issue in a much simplified state from the
original application. The issue can be reproduced simply by running the
SecuredServiceTest
which results ina
RuntimeException
to be thrown statingjava.lang.RuntimeException: Collection already filtered.
. The components ofthe test are:
org.radickins.ssa
to component scan and@EnableMethodSecurity
org.radickins.ssa.security
implementing thePermissionEvaluator
and
MethodSecurityExpressionHandler
org.radickins.ssa.service
with a simple API annotated with@PostFilter
Given the
SecuredService
API that is annotated with@PostFilter
is entirely self-contained in a simpleimplementation, we expect the result to be filtered only once by the Spring Security framework. The permission evaluator
marks each object that should be filtered as having been filtered, and the expression handler raises an exception if it
detects the
filterTarget
has already been filtered. If working correctly, the expectation is the test should pass asfiltering only occurs once.
Investigation
I have not attempted to fix the issue, but I believe the cause to be due to the bean registration of
the
PostFilterAuthorizationMethodInterceptor
bean. ThePrePostMethodSecurityConfiguration
configuration declares thepostFilterAuthorizationMethodInterceptor
bean as an
Advisor
type, and as you can see the other interceptors forPreFilter
,PreAuthorize
,and
PostAuthorize
are each declared asMethodInterceptor
types.All of these interceptors are registered again as
Advisor
beans usingthe MethodSecurityAdvisorRegistrar
When the secured proxy is built, methods annotated with
@PostFilter
are assigned anyAdvisor
beans required toprocess the AOP security proxy invocation, and the
PostFilterAuthorizationMethodInterceptor
is added twice (as shownin the image below taken from debugging a breakpoint in the
CustomExpressionHandler
).I believe the fix is to simply register the
PostFilterAuthorizationMethodInterceptor
as theMethodInterceptor
typein the
PrePostMethodSecurityConfiguration
config.The text was updated successfully, but these errors were encountered: