Protection against cross-site request forgery is turned off
What it finds
Cross-site request forgery protection makes the browser prove that a state-changing request comes from the application's own pages. Without it, any site the user visits while signed in can submit forms to the application in the user's name, as the browser adds the session cookie by itself. Turning it off is only safe for endpoints that no browser session can reach, as APIs authenticated by a header token.
Reported for csrf { disable() }, csrf { it.disable() }, .csrf().disable() and csrf(AbstractHttpConfigurer::disable) in files that import Spring Security.
From the rule's source, csrf_disabled.rs.
import org.springframework.security.config.annotation.web.builders.HttpSecurity class Security { fun chain(http: HttpSecurity) { http { csrf { disable() }tx0 reports: CSRF protection is turned off } http.csrf { it.disable() }tx0 reports: CSRF protection is turned off http.csrf().disable()tx0 reports: CSRF protection is turned off http.csrf(AbstractHttpConfigurer::disable)tx0 reports: CSRF protection is turned off http.csrf { it.ignoringRequestMatchers("/webhook") } http.cors { it.disable() } }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:csrf-protection-disabled" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:csrf-protection-disabled] reason="..."tx0 explain tx0/kotlin:csrf-protection-disabled shows the same in the terminal. Found a false positive? Report it.