Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5b5308

Browse files
committed
python: require authentication middleware
for CSRF to be relevant
1 parent 895ce75 commit f5b5308

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

python/ql/lib/semmle/python/frameworks/Django.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,15 +2326,16 @@ module PrivateDjango {
23262326
DjangoSettingsMiddlewareStack() {
23272327
this.asExpr() = list and
23282328
// we look for an assignment to the `MIDDLEWARE` setting
2329-
exists(DataFlow::Node mw, string djangomw |
2329+
exists(DataFlow::Node mw |
23302330
mw.asVar().getName() = "MIDDLEWARE" and
23312331
DataFlow::localFlow(this, mw)
23322332
|
2333-
// check that the list contains at least one reference to `django`
2334-
list.getAnElt().(StrConst).getText() = djangomw and
2335-
// TODO: Consider requiring `django.middleware.security.SecurityMiddleware`
2336-
// or something indicating that a security middleware is enabled.
2337-
djangomw.matches("django.%")
2333+
// it only counts as setting the CSRF protection, if the app uses authentication,
2334+
// so check that the list contains the django authentication middleware.
2335+
//
2336+
// This also strongly implies that we are actually looking at the `MIDDLEWARE` setting.
2337+
list.getAnElt().(StrConst).getText() =
2338+
"django.contrib.auth.middleware.AuthenticationMiddleware"
23382339
)
23392340
}
23402341

0 commit comments

Comments
 (0)