spring-projects / spring-projects/spring-security

filter is applied to paths that should be allowed in http security configuration with new SS 6.4.3

Open
#16,703 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
this is how I configure http security using the SS 6.4.3

  @Bean
  open fun securityFilterChain(http: HttpSecurity, authManager: AuthenticationManager): SecurityFilterChain {
    http {
      authorizeHttpRequests {
        authorize(HttpMethod.OPTIONS, "/**", permitAll)
         authorize(HttpMethod.GET, "/swagger-ui.html", permitAll)       
        authorize(anyRequest, authenticated)
      }
      csrf { disable() }
      sessionManagement {
        sessionCreationPolicy = SessionCreationPolicy.STATELESS
      }
      addFilterBefore<AuthorizationFilter>(MyFilter(processor, authManager))
    }
    return http.build()
  }

even though '/swagger-ui.html' is configured to skip authentication, MyFilter is found applied to /swagger-ui.html. It was not the case with SS 5.4

if I enable debug in security config, here is the list of filters applied to '/swagger-ui/*'

servletPath:/swagger-ui/swagger-ui.css
pathInfo:null
headers:
host: localhost:8090
connection: keep-alive
sec-ch-ua-platform: "macOS"
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
sec-ch-ua: "Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"
sec-ch-ua-mobile: ?0
accept: /
sec-fetch-site: same-origin
sec-fetch-mode: cors
sec-fetch-dest: empty
referer: http://localhost:8090/
accept-encoding: gzip, deflate, br, zstd
accept-language: en-US,en;q=0.9

Security filter chain: [
DisableEncodeUrlFilter
WebAsyncManagerIntegrationFilter
SecurityContextHolderFilter
HeaderWriterFilter
LogoutFilter
MyFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
AuthorizationFilter
]

To Reproduce
Steps to reproduce the behavior.

Expected behavior
filter added later should NOT be applied to paths configured with permitAll

Sample

A link to a GitHub repository with a minimal, reproducible sample.

Reports that include a sample will take priority over reports that do not.
At times, we may require a sample, so it is good to try and include a sample up front.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided SecurityFilterChain configuration, focusing on authorizeHttpRequests, addFilterBefore, and the custom MyFilter. Reproduce requests to /swagger-ui.html and /swagger-ui/* with Spring Security 6.4.3 and compare the listed filter chains with the expected permitAll behavior. Done means the later-added filter is not applied to paths configured with permitAll.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin, spring
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.