Repository navigation
SONARJAVA-6615 S4502 should not raise when the app is stateless with token-based auth - #6511
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aurelien-coet-sonarsource
left a comment
There was a problem hiding this comment.
LGTM. Just a tiny nit, but feel free to ignore.
| return http.build(); | ||
| } | ||
|
|
||
| org.springframework.security.config.Customizer<org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer<HttpSecurity>> resourceServerCustomizer() { |
There was a problem hiding this comment.
Nit: is there a reason to use the fully qualified names here ?
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findingsExpanding S4502 suppression for stateless OAuth2 resource-server chains could hide CSRF findings when the analyzer misidentifies chain configuration. Exempts stateless OAuth2 resource-server ✅ 1 closed✅ Edge Case: Browser-auth denylist misses x509/jee, so these chains are still exempted
Verification Rules 2/2 met Repos 5 inspected · PRs 2 inspectedFunctional validation No results Rules 2 passed 2 not applicable
Broader impact Repos 5 inspected PRs 2 inspectedCross-repo 5 repositories inspected 0 open impacts
Cross-PR 2 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




What
S4502 (
SpringSecurityDisableCSRFCheck) no longer raises on aSecurityFilterChainbean that fully disables CSRF when the sameHttpSecuritybuilder also:SessionCreationPolicy.STATELESS,oauth2ResourceServer(...), andformLogin(),httpBasic(),rememberMe()oroauth2Login().Full-disable forms that can be suppressed:
.disable()(member select or customizer lambda),AbstractHttpConfigurer::disable, andrequireCsrfProtectionMatcher(request -> false).Decisions to review
httpBasic(AbstractHttpConfigurer::disable),formLogin(f -> f.disable())andrememberMe().disable()do not block the exemption. This is broader than the ticket's literal wording ("does not configure"), chosen because it is a very common shape in stateless JWT configs. Enabled forms (httpBasic(withDefaults()),httpBasic(b -> b.realmName(..)), no-arghttpBasic()) still raise.@BeanreturningSecurityFilterChain, with a singleHttpSecurityparameter, a singlereturnof that builder, and only expression or return statements at top level.httpmust only be used as a call receiver, and the session and resource-server customizers must be lambdas orwithDefaults(). Anything else keeps raising, for example a builder passed to a helper, an aliased builder, conditional or deferredsessionCreationPolicy, a later policy override, a disabled resource server, orgetSharedObject. One known consequence: a local variable declaration in the bean method keeps the issue raised.Out of scope (still raises)
ignoringRequestMatchers(...),ignoringAntMatchers(...),requireCsrfProtectionMatcher(<anything other than r -> false>).oauth2ResourceServer(follow-up per ticket).WebSecurityConfigurerAdapter.configure(HttpSecurity).Open question for rule owners (from the ticket, not blocking)
Several reviewers resolved this STATELESS + JWT shape as WONTFIX to keep it visible rather than suppressed. Please confirm that dropping the finding entirely for this shape is the intended outcome.
Tests
SpringSecurityDisableCSRFCheckSamplecovers each Definition of Done case. Each must-still-raise case differs from a compliant base in exactly one condition, so a case cannot pass just because a base condition failed to resolve.test_without_semanticstill expects no issues.Locally (JDK 21):
SpringSecurityDisableCSRFCheckTest: 2/2 tests pass.java-checks-test-sources/defaultclasspath (Spring Security config 5.8.11) with no new dependencies.Not verified locally: a full build of
java-checks-test-sources(it needs JDK 26), the ruling results (mallhas S4502 expectations; any removed findings need a check that they are real stateless resource-server chains), and the autoscan IT.🤖 Generated with Claude Code