File tree Expand file tree Collapse file tree
python/ql/lib/semmle/python/frameworks Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments