File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
python/ql/src/Security/CWE-352 Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 14
14
import python
15
15
import semmle.python.Concepts
16
16
17
- from HTTP:: Server:: CsrfProtectionSetting s
18
- where
19
- s .getVerificationSetting ( ) = false and
20
- not exists ( HTTP:: Server:: CsrfLocalProtectionSetting p | p .csrfEnabled ( ) ) and
17
+ predicate relevantSetting ( HTTP:: Server:: CsrfProtectionSetting s ) {
21
18
// rule out test code as this is a common place to turn off CSRF protection.
22
19
// We don't use normal `TestScope` to find test files, since we also want to match
23
20
// a settings file such as `.../integration-tests/settings.py`
24
21
not s .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) .matches ( "%test%" )
25
- select s , "Potential CSRF vulnerability due to forgery protection being disabled or weakened."
22
+ }
23
+
24
+ predicate vulnerableSetting ( HTTP:: Server:: CsrfProtectionSetting s ) {
25
+ s .getVerificationSetting ( ) = false and
26
+ not exists ( HTTP:: Server:: CsrfLocalProtectionSetting p | p .csrfEnabled ( ) ) and
27
+ relevantSetting ( s )
28
+ }
29
+
30
+ from HTTP:: Server:: CsrfProtectionSetting setting
31
+ where
32
+ vulnerableSetting ( setting ) and
33
+ // We have seen examples of dummy projects with vulnerable settings alongside a main
34
+ // project with a protecting settings file. We want to rule out this scenario, so we
35
+ // require all non-test settings to be vulnerable.
36
+ forall ( HTTP:: Server:: CsrfProtectionSetting s | relevantSetting ( s ) | vulnerableSetting ( s ) )
37
+ select setting , "Potential CSRF vulnerability due to forgery protection being disabled or weakened."
You can’t perform that action at this time.
0 commit comments