Skip to content

Do not validate ignoredRequests from WebSecurity.ignoring() #17158

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,6 +52,9 @@ public void validate(FilterChainProxy filterChainProxy) {
private void checkForAnyRequestRequestMatcher(List<SecurityFilterChain> chains) {
DefaultSecurityFilterChain anyRequestFilterChain = null;
for (SecurityFilterChain chain : chains) {
if (isWebIgnoredRequests(chain)) {
continue;
}
if (anyRequestFilterChain != null) {
String message = "A filter chain that matches any request [" + anyRequestFilterChain
+ "] has already been configured, which means that this filter chain [" + chain
Expand All @@ -69,6 +72,9 @@ private void checkForAnyRequestRequestMatcher(List<SecurityFilterChain> chains)
private void checkForDuplicateMatchers(List<SecurityFilterChain> chains) {
DefaultSecurityFilterChain filterChain = null;
for (SecurityFilterChain chain : chains) {
if (isWebIgnoredRequests(chain)) {
continue;
}
if (filterChain != null) {
if (chain instanceof DefaultSecurityFilterChain defaultChain) {
if (defaultChain.getRequestMatcher().equals(filterChain.getRequestMatcher())) {
Expand Down Expand Up @@ -110,4 +116,8 @@ private void checkAuthorizationFilters(List<SecurityFilterChain> chains) {
}
}

private boolean isWebIgnoredRequests(SecurityFilterChain chain) {
return chain.getFilters().isEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -142,6 +142,32 @@ public void defaultFiltersPermitAll() throws IOException, ServletException {
assertThat(response.getRedirectedUrl()).isEqualTo("/login?logout");
}

@Test
public void validateWhenUseIgnoredRequests() {
this.spring.register(FilterChainProxyWithWebSecurityCustomizer.class);
List<SecurityFilterChain> filterChains = this.spring.getContext()
.getBean(FilterChainProxy.class)
.getFilterChains();
assertThat(filterChains.size()).isEqualTo(2);
}

@Configuration
@EnableWebSecurity
@EnableWebMvc
static class FilterChainProxyWithWebSecurityCustomizer {

@Bean
WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().anyRequest();
}

@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests((a) -> a.anyRequest().authenticated()).build();
}

}

@Configuration
@EnableWebSecurity
static class FilterChainProxyBuilderMissingConfig {
Expand Down