-
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
AuthorizationFilter
behaves different from FilterSecurityInterceptor
for requests without bearer token
#12278
Comments
Thanks for the report @vpavic. Investigating a bit more, this is not only related to a resource server, if any kind of authentication is being used, like This is happening because when you POST without a CSRF token, the If we configure it like the below, the http
.authorizeHttpRequests((requests) -> requests
.shouldFilterAllDispatcherTypes(true)
.anyRequest().authenticated()
)
// ... or, with Spring Security >= 5.6.9 http
.authorizeHttpRequests((requests) -> requests
.anyRequest().authenticated()
.withObjectPostProcessor(new ObjectPostProcessor<AuthorizationFilter>() {
@Override
public <O extends AuthorizationFilter> O postProcess(O object) {
object.setFilterErrorDispatch(true);
return object;
}
})
)
// ... I wonder if we should change the Line 58 in 9b3f834
|
Thanks for the feedback. Yes, I was aware this isn't specific to resource server, sorry for being perhaps too focused on the concrete setup I was working with when facing this issue. Honestly, while I was troubleshooting this I completely forgot about |
Yes, I agree. That's why I prefer Rob's input on this first. He is on PTO this week but we will talk when he is back. |
Though this ticket is focused on 5.7, this portion of the 5.8 migration guide may be helpful for additional context. |
Hi @vpavic, I've talked to @rwinch, and indeed we should not change the default given that we have ways to configure the filter to behave as we want. I'm only curious what has made you switch from |
I am an unrelated observer/subscriber to this issue, but for what it's worth, I myself switched because after upgrading to Spring Boot 3 and Spring Security 6, I noticed that my IDE stated that I wouldn't be surprised if others have done the same. Thank you all for working on this project! (Also unrelated: the most confusing/time-consuming aspect of the migration was trying to figure out why some routes were failing authorization even though clearly authorized, logs would show that authorization passed but then the filter would somehow re-run for the same request and that one failed authorization. It ended up being related to the change that the filter runs for all dispatcher types now, I believe, and "fixed" it by setting |
Thanks for your input @blaenk. Yes, we are aware that most users will migrate because of the deprecation notice. Did you see the Preparing for 6.0 section of Spring Security 5.8 documentation? There you have all the steps necessary to prepare for 6.0 changes, including the filter all dispatcher types. You might want to permit forward dispatch if you are using Spring MVC to resolve view names, or async dispatch if using |
Ah I'm sorry I had not, that's on me. Thank you for pointing that out, I will go through it.
Thank you so much for this advice. I will read the "preparing for 6.0" section you linked and then re-read your advice. I think the documentation is really great. I think it was more that I missed that note/link, or I think I saw it but mistakenly interpreted that it was not relevant to "Migrating to 6.0". I assumed the section was self-contained. Thanks again for that info and for working on this project! |
I'll close this as solved but feel free to continue the discussion. |
I'm observing this with Spring Boot 2.7.5 (Spring Security 5.7.4).
Consider the following minimal resource server application:
Issuing
POST
request to/
without authorization header will result in401
, as expected.However, if
AuthorizationFilter
is used by changingSecurityFilterChain
bean to this:Then the same request will result in
403
.I didn't dig too deep, but I observed that in first case
FilterChain#doFilter
invocation inExceptionTranslationFilter#doFilter
will throwAccessDeniedException
which in turn results in invocation ofBearerTokenAuthenticationEntryPoint
, while in second case the sameFilterChain#doFilter
invocation inExceptionTranslationFilter#doFilter
won't throw an exception.The text was updated successfully, but these errors were encountered: