Skip to content

Commit 2d3d49f

Browse files
authored
Merge pull request github#16628 from mbaluda/main
Disable csrf for ServerHttpSecurity
2 parents 61593ae + 48fc44b commit 2d3d49f

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

java/ql/lib/semmle/code/java/security/SpringCsrfProtection.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,18 @@ predicate disablesSpringCsrfProtection(MethodCall call) {
1717
.getReferencedCallable()
1818
.hasQualifiedName("org.springframework.security.config.annotation.web.configurers",
1919
"AbstractHttpConfigurer", "disable")
20+
or
21+
call.getMethod().hasName("disable") and
22+
call.getReceiverType()
23+
.hasQualifiedName("org.springframework.security.config.web.server",
24+
"ServerHttpSecurity$CsrfSpec")
25+
or
26+
call.getMethod()
27+
.hasQualifiedName("org.springframework.security.config.web.server", "ServerHttpSecurity",
28+
"csrf") and
29+
call.getArgument(0)
30+
.(MemberRefExpr)
31+
.getReferencedCallable()
32+
.hasQualifiedName("org.springframework.security.config.web.server",
33+
"ServerHttpSecurity$CsrfSpec", "disable")
2034
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `java/spring-disabled-csrf-protection` detects disabling CSRF via `ServerHttpSecurity$CsrfSpec::disable`.
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
22
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
3+
import org.springframework.security.config.web.server.ServerHttpSecurity;
34

45
public class SpringCsrfProtectionTest {
5-
protected void test(HttpSecurity http) throws Exception {
6+
protected void test(HttpSecurity http, final ServerHttpSecurity httpSecurity) throws Exception {
67
http.csrf(csrf -> csrf.disable()); // $ hasSpringCsrfProtectionDisabled
78
http.csrf().disable(); // $ hasSpringCsrfProtectionDisabled
89
http.csrf(AbstractHttpConfigurer::disable); // $ hasSpringCsrfProtectionDisabled
10+
11+
httpSecurity.csrf(csrf -> csrf.disable()); // $ hasSpringCsrfProtectionDisabled
12+
httpSecurity.csrf().disable(); // $ hasSpringCsrfProtectionDisabled
13+
httpSecurity.csrf(ServerHttpSecurity.CsrfSpec::disable); // $ hasSpringCsrfProtectionDisabled
914
}
10-
}
15+
}

java/ql/test/stubs/springframework-5.3.8/org/springframework/security/config/web/server/ServerHttpSecurity.java

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)