False positive Java. SpringBoot CSRF
- Lingua principale
- CodeQL
- Stelle
- 10.1k
- Fork
- 2.1k
- Merge medio
- 2g 15h
- PR unite (30g)
- 141
Descrizione
**Description of the false positive**
Given a SpringBoot application that acts solely as an API/OIDC Resource Server and does not utilize cookies or state, where CSRF is disabled, the `CodeQL / Disabled Spring CSRF protection` should not be triggered.
**Code samples or links to source code**
```Java
@Bean
SecurityFilterChain securityFilterChain(
final HttpSecurity http,
final String privateScope,
final AppUserPrincipalJwtAuthenticationConverter appUserPrincipalJwtAuthenticationConverter) {
http.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable) // NOSONAR stateless JWT, no CSRF cookies
.logout(AbstractHttpConfigurer::disable)
.sessionManagement(
session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize ->
authorize
.dispatcherTypeMatchers(DispatcherType.ERROR, DispatcherType.FORWARD)
.permitAll()
.requestMatchers(RuntimeEndpointPaths.unauthenticatedPaths())
.permitAll()
.requestMatchers(
new RegexRequestMatcher(
RuntimeEndpointPaths.versionedInternalRouteRegex(), null))
.access(interactiveUserAuthorizationManager())
.requestMatchers(
new RegexRequestMatcher(
RuntimeEndpointPaths.versionedPrivateRouteRegex(), null))
.access(
callerTypeAuthorizationManager(
OidcCallerType.CLIENT_CREDENTIALS, privateScope))
.anyRequest()
.authenticated())
.oauth2ResourceServer(
oauth2 ->
oauth2.jwt(
jwt ->
jwt.jwtAuthenticationConverter(
appUserPrincipalJwtAuthenticationConverter)));
return http.build();
}
```
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start by locating the CodeQL query named "Disabled Spring CSRF protection" and review how it identifies Spring Security configurations. Reproduce the provided stateless JWT/OIDC resource-server example, then verify that disabling CSRF no longer triggers the query for this configuration while the reported case remains covered.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, spring-boot
- Ambito
- backend, security
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100