-
Notifications
You must be signed in to change notification settings - Fork 6k
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
WARN when ignoring antMatchers - please use permitAll #10938
Comments
Hi, @pblanchardie, good question.
If needed, you can use In the meantime, if you don't want the warning message and you need the performance optimization, you can introduce a second filter chain for static resources like so: @Bean
@Order(0)
SecurityFilterChain resources(HttpSecurity http) throws Exception {
http
.requestMatchers((matchers) -> matchers.antMatchers("/static/**"))
.authorizeHttpRequests((authorize) -> authorize.anyRequest().permitAll())
.requestCache().disable()
.securityContext().disable()
.sessionManagement().disable();
return http.build();
} This second filter chain will secure the static resources without reading the |
Hi @jzheaux thanks a lot for your quick answer, explanation and tips. It makes sense now! |
Hi I've noticed the warnings in my logs today. My problem with the permitAll approach is that if a token (or other mean of authentication) is sent on a request, the code will try to authenticate the request. This could mean a call to an external service, or redis for a session cookie, or some other service. And if that authentication token is not valid, the user will receive a 401. So, for example, if you have a path From a resiliency perspective, if I use a session that is backed by a redis server and that server is down, it will throw an exception and my users won't be able to access static resources or any path that the session is not strictly required. Will #10913 fix this behavior? Thanks! |
Hi @jebeaudet, have you disabled the following Configurers for your http
.requestMatchers((matchers) -> matchers.antMatchers("/static/**"))
.authorizeHttpRequests((authorize) -> authorize.anyRequest().permitAll())
.requestCache().disable()
.securityContext().disable()
.sessionManagement().disable(); With those configurations disabled, Spring Security will not look up the session and, therefore, will not try to authenticate the user. And yes, #10913 will fix that. |
Hi @marcusdacoregio, thanks for chiming in. Reading your message made me realize that Josh also put those The web ignoring way was straightforward. Also, the log message does not mention the Good news that #10913 will fix that, however I'm curious as to whether it'll cover the Thanks again |
@marcusdacoregio sorry for the ping but would you have a chance to answer my question? Thanks |
When I use
web.ignoring().antMatchers()
I'd like to see a DEBUG message instead of a WARNING for each ignored pattern.I'm confused by the message saying it's not recommended and I should use permitAll instead, as I don't want Spring Security filter chain on these paths.
Since a09f6e1, there is a WARNING for each ignored pattern saying:
You are asking Spring Security to ignore Ant [pattern='/foo.bar']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
Before that, we had no warning.
Why is ignoring antMatchers not recommended anymore? Why should I prefer permitAll for eg. static resources?
The text was updated successfully, but these errors were encountered: