Java: Improve java/spring-disabled-csrf-protection

This commit is contained in:
Tony Torralba
2023-10-16 15:49:25 +02:00
parent 1297acf5b1
commit d08ee76b16
10 changed files with 78 additions and 6 deletions

View File

@@ -0,0 +1,2 @@
testFailures
failures

View File

@@ -0,0 +1,10 @@
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
public class SpringCsrfProtectionTest {
protected void test(HttpSecurity http) throws Exception {
http.csrf(csrf -> csrf.disable()); // $ hasSpringCsrfProtectionDisabled
http.csrf().disable(); // $ hasSpringCsrfProtectionDisabled
http.csrf(AbstractHttpConfigurer::disable); // $ hasSpringCsrfProtectionDisabled
}
}

View File

@@ -0,0 +1,18 @@
import java
import semmle.code.java.security.SpringCsrfProtection
import TestUtilities.InlineExpectationsTest
module SpringCsrfProtectionTest implements TestSig {
string getARelevantTag() { result = "hasSpringCsrfProtectionDisabled" }
predicate hasActualResult(Location location, string element, string tag, string value) {
tag = "hasSpringCsrfProtectionDisabled" and
exists(MethodAccess call | disablesSpringCsrfProtection(call) |
call.getLocation() = location and
element = call.toString() and
value = ""
)
}
}
import MakeTest<SpringCsrfProtectionTest>

View File

@@ -0,0 +1 @@
semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/springframework-5.3.8