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 1414import python
1515import semmle.python.Concepts
1616
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 ) {
2118 // rule out test code as this is a common place to turn off CSRF protection.
2219 // We don't use normal `TestScope` to find test files, since we also want to match
2320 // a settings file such as `.../integration-tests/settings.py`
2421 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