spring-projects / spring-projects/spring-security

Consider warning users if securityMatchers do not match some filter in the chain

Open
#14,096 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: config status: ideal-for-contribution type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
HttpSecurity configuration with securityMatcher and oauth2Login(withDefaults()) leads to 404 for some OAuth2 endpoints.

To Reproduce

  1. Clone this repo: https://github.com/Haarolean/spring-security-matchers-bug
  2. Run the app
  3. Go to http://localhost:8080/oauth2/authorization/github
  4. Observe 404

Also,

  1. Commenting line 25 in OAuthSecurityConfig fixes the issue.
  2. Endpoint like http://localhost:1337/login/oauth2/code/github?code=xxx still works for some reason.
  3. I've traced the issue down to MvcRequestMatcher, where notMatchMethodOrServletPath always results in true. Without line 25, MvcRequestMatcher is not used, rather AnyRequestMatcher is being used.
  4. I've dug through all the possible documentation on securityMatcher and didn't find anything which could explain the problem.

Expected behavior
oauth, csrf, cors and other configurations are applied only for /api/web/**.

Sample

https://github.com/Haarolean/spring-security-matchers-bug

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 linked reproduction, run the app, and inspect line 25 of OAuthSecurityConfig. Trace how MvcRequestMatcher and AnyRequestMatcher affect the filter chain for /oauth2/authorization/github and the callback endpoint. Done means the configuration behavior is explained and the proposed warning or related handling is covered by appropriate project tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.