Consider warning users if securityMatchers do not match some filter in the chain
Author: HaaroleanCreated Nov 4, 2023Updated Sep 15, 2026
Labelsin: configtype: enhancementstatus: ideal-for-contribution
Describe the bug
HttpSecurity configuration with securityMatcher and oauth2Login(withDefaults()) leads to 404 for some OAuth2 endpoints.
To Reproduce
- Clone this repo: https://github.com/Haarolean/spring-security-matchers-bug
- Run the app
- Go to
http://localhost:8080/oauth2/authorization/github - Observe 404
Also,
- Commenting line 25 in
OAuthSecurityConfigfixes the issue. - Endpoint like
http://localhost:1337/login/oauth2/code/github?code=xxxstill works for some reason. - I've traced the issue down to
MvcRequestMatcher, wherenotMatchMethodOrServletPathalways results intrue. Without line 25,MvcRequestMatcheris not used, ratherAnyRequestMatcheris being used. - I've dug through all the possible documentation on
securityMatcherand didn't find anything which could explain the problem.
Expected behavior
oauth, csrf, cors and other configurations are applied only for /api/web/**.
Sample
Source: spring-projects/spring-security