Skip to content

Commit e2479a7

Browse files
committed
Disable csrf for ServerHttpSecurity
1 parent 61593ae commit e2479a7

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import java
55
/** Holds if `call` disables CSRF protection in Spring. */
66
predicate disablesSpringCsrfProtection(MethodCall call) {
77
call.getMethod().hasName("disable") and
8-
call.getReceiverType()
9-
.hasQualifiedName("org.springframework.security.config.annotation.web.configurers",
10-
"CsrfConfigurer<HttpSecurity>")
8+
(
9+
call.getReceiverType()
10+
.hasQualifiedName("org.springframework.security.config.annotation.web.configurers",
11+
"CsrfConfigurer<HttpSecurity>")
12+
or
13+
call.getReceiverType()
14+
.hasQualifiedName("org.springframework.security.config.web.server",
15+
"ServerHttpSecurity$CsrfSpec")
16+
)
1117
or
1218
call.getMethod()
1319
.hasQualifiedName("org.springframework.security.config.annotation.web.builders",
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)