Cross Site Request Forgery protection not activated

Your website is vulnerable to CSRF attacks because the MIDDLEWARE setting is missing CsrfViewMiddleware - so a hacker can fool your website into thinking a request is coming from a logged in user.

If unprotected, when one of your logged-in users accesses a malicious website, that website can perform a request to your website and your website will think the request was performed by the user.

This can be avoided by using CSRF protection - which adds a cycling string to forms on your website. Django then checks if the submitted string is as expected. If it's not then the request probably did not come from your website.

Additionally, making sure that GET request are free from side-effects (so don't submit a form that creates a database entry on GET) helps avoud this problem.

So in practice, do this


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
]

Instead of this


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
]

Are you affected by this? Audit your codebase in seconds to find out.

Configuring this check

Django Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code missing-csrf-middleware in your pyproject.toml file.

Read more about configuring Django Doctor.