Skip to main content
Platform security guideReviewed

Django security in production: settings, middleware, admin and raw SQL

Django includes many security features, some always on and some optional, and its deployment checklist includes settings that must be set properly for Django to provide the expected level of security.

This guide covers what manage.py check --deploy reports and what it leaves out, the settings and middleware that matter in production, the admin site, uploaded media and raw SQL, and comes with an evidence matrix you fill in for your own project, including two-user permission tests.

Django deployment evidence matrix

Paste the table into a spreadsheet, keep a separate copy for each environment, and fill the rows in order. Each row says where to look in your own project, what the Django documentation says about it, what to write down and the evidence to keep.

How to use it

Every step reads a setting, file, list or response, and the two-user rows use test accounts you create in a staging environment you control and only view pages. For each secret, write down that it is set, the place it is loaded from and who has read access to that place, and leave its value out. Documentation details are as the Django 6.1 documentation and djangoproject.com gave them on 14 November 2026.

15 rows

Django deployment evidence matrix

AreaWhere to lookWhat the Django documentation saysWhat to recordEvidence to keep
manage.py check --deployRun python manage.py check --deploy where the production settings load: on the production or staging server, or with --settings set to the production settings module. Also read SILENCED_SYSTEM_CHECKS.The django-admin reference says --deploy activates some additional checks that are only relevant in a deployment setting, and that development settings may not have many production settings. The system check reference says the security checks do not audit code and help perform a low-hanging-fruit checklist. --fail-level defaults to ERROR, and all of the --deploy security checks except security.E023 and security.E024 are warnings.The exact command, the settings module it used, each message with its id, and each silenced id with the reason it is silenced.The output pasted as printed, with the date, the environment and the Django version. No settings edited during the review to clear a warning.
Settings module and DEBUGDJANGO_SETTINGS_MODULE in the environment of the production process, the settings file it names, and the line that sets DEBUG.Per the deployment checklist, debug must never be enabled in production: it leaks lots of information about the project, with source code excerpts, local variables, settings and the libraries in use among its examples. The settings reference notes that the settings.py startproject creates sets DEBUG = True. security.W018 reports DEBUG left on.The module path, whether DEBUG is a literal or read from the environment, and its value in production.File path and line number, and the security.W018 result from the first row.
SECRET_KEY and SECRET_KEY_FALLBACKSFirst, a search of tracked settings files that reports only the file and line number of any line assigning a literal value, never the matched text. Then, for a key loaded from elsewhere, the settings line that loads it and the name of the environment variable, file path or secrets store entry it reads from, without opening that file or entry.The checklist asks for a large random value, kept secret, not used anywhere else and not committed to source control. The settings reference says a known key can lead to privilege escalation and remote code execution vulnerabilities, and that old keys come out of SECRET_KEY_FALLBACKS when you are ready to expire what they signed. security.W009 and security.W025 report short, low-variety or django-insecure- keys.That each is set, where it is loaded from, who can read that place, any tracked file and line that assigns a literal value, and how many fallback keys there are.Names, locations and people only. Never the key, and no command, shell or debug page that prints settings.
ALLOWED_HOSTS and forwarded host headersALLOWED_HOSTS and USE_X_FORWARDED_HOST in the production settings, and the default server or virtual host of the web server in front of Django.Per the checklist, once DEBUG = False a suitable value is required or Django does not work at all; with a wildcard, validating the Host header becomes your job unless you otherwise ensure you are not vulnerable to that category of attacks; and requests for incorrect hosts should get a static error page from the web server ahead of Django, or be ignored there, rather than being forwarded to Django. The settings reference says USE_X_FORWARDED_HOST should only be enabled if a proxy which sets the header is in use. The security.W020 message says only that ALLOWED_HOSTS must not be empty in deployment.Each entry and the site it serves, any '*' or leading-period wildcard, the value of USE_X_FORWARDED_HOST, and the proxy that sets that header.Settings and web server excerpts. The Host header injection guide covers testing how the site responds.
HTTPS, proxy header and cookie flagsSECURE_SSL_REDIRECT, SECURE_PROXY_SSL_HEADER, SESSION_COOKIE_SECURE, SESSION_COOKIE_HTTPONLY and CSRF_COOKIE_SECURE, plus the load balancer or proxy configuration.The checklist says any website which allows users to log in should enforce site-wide HTTPS, and to set CSRF_COOKIE_SECURE and SESSION_COOKIE_SECURE once HTTPS is set up. The settings reference says to set SECURE_PROXY_SSL_HEADER only if you control your proxy or can otherwise be sure that it sets or strips the header appropriately, and warns that modifying it can compromise your site's security. Checks: security.W008 and security.W010 to security.W016.Each value, the layer that redirects HTTP to HTTPS, and, if SECURE_PROXY_SSL_HEADER is set, the header and the proxy that strips it from incoming requests.Settings and proxy excerpts, and the Set-Cookie attributes seen in the browser's developer tools when a test account signs in.
SecurityMiddleware and its headersMIDDLEWARE; SECURE_HSTS_SECONDS, SECURE_HSTS_INCLUDE_SUBDOMAINS, SECURE_HSTS_PRELOAD, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_REFERRER_POLICY and SECURE_CROSS_ORIGIN_OPENER_POLICY; and the response headers of one Django page and one static or uploaded file.Without the middleware, security.W001 says SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_REFERRER_POLICY, SECURE_CROSS_ORIGIN_OPENER_POLICY and SECURE_SSL_REDIRECT will have no effect. In the 6.1 settings reference, nosniff defaults to True and both policies to 'same-origin', while SECURE_HSTS_SECONDS defaults to 0. The middleware reference suggests the front-end server perform the same functions where the deployment allows, and warns that HSTS applies to the entire domain. Checks: security.W004 to security.W006, security.W021, security.W022, security.E023 and security.E024.Whether and where SecurityMiddleware sits in MIDDLEWARE, each setting's value, and the headers each of the two responses actually carried.Both sets of response headers, read in the browser's developer tools, with the URL and date.
CSRF, clickjacking and CSP middlewareThe full MIDDLEWARE list in order, X_FRAME_OPTIONS, and SECURE_CSP and SECURE_CSP_REPORT_ONLY if present.security.W002 and security.W003 report XFrameOptionsMiddleware or CsrfViewMiddleware missing, and security.W019 reports XFrameOptionsMiddleware present with X_FRAME_OPTIONS set to something other than 'DENY', its default. ContentSecurityPolicyMiddleware, new in Django 6.0, sets CSP headers from SECURE_CSP and SECURE_CSP_REPORT_ONLY. The ordering notes put SecurityMiddleware near the top when the SSL redirect is on, and CsrfViewMiddleware before view middleware that assumes CSRF attacks have been dealt with.The ordered list, which of XFrameOptionsMiddleware, CsrfViewMiddleware and ContentSecurityPolicyMiddleware are present, and the X_FRAME_OPTIONS and CSP settings.Settings excerpt with the date.
CSRF_TRUSTED_ORIGINS and exempt viewsCSRF_TRUSTED_ORIGINS in the production settings, and a code search for csrf_exempt.CSRF_TRUSTED_ORIGINS defaults to an empty list and supports subdomain wildcards such as https://*.example.com. The middleware checks the Origin header, if the browser provides one, against the current host and this list. The CSRF reference says subdomains that can set cookies for the whole domain can, with a corresponding token, circumvent the protection, and the security overview says to be very careful with marking views csrf_exempt unless it is absolutely necessary.Each origin with the business or service that owns it and why it posts to this site, and each exempt view with its URL and the check that replaces CSRF protection, such as a webhook signature.The list with file and line references, and the person who confirmed each reason.
Admin site access and staff accountsThe URLconf line that includes admin.site.urls, anything in front of that path such as an address restriction, and the user and group lists in the admin.The admin reference says its recommended use is an organisation's internal management tool, that login needs is_staff by default, and that has_permission() defaults to requiring both is_active and is_staff. The authentication guide says admin access is granted per type of object through the view, add, change and delete permissions.The admin path, any restriction in front of it, every staff and superuser account matched to a named person, and each group's permissions per model.A dated export or screenshot of the user and group lists, with personal details trimmed.
Admin actionsEach ModelAdmin's actions attribute, the action decorator's permissions argument, and site-wide actions added with AdminSite.add_action() or removed with AdminSite.disable_action().Django ships a "delete selected objects" action available to all models; it uses QuerySet.delete(), so model delete() methods are not called. The permissions argument limits who is offered an action. The admin does not automatically check object-level permissions for each selected object when executing an action; to limit which objects an action may modify on that basis, the reference says to perform those checks in the action itself.One line per action: its model, its permissions, whether the code checks each object, and whether it updates or deletes in bulk.Code references by file and line.
User-uploaded mediaMEDIA_ROOT, MEDIA_URL and STATIC_ROOT, the web server or storage configuration for the media path, any static() line in urls.py, and the web server's request body limit.The checklist calls media untrusted and says to make sure the web server never attempts to interpret it. The static files guide says serving uploads with django.views.static.serve() is not suitable for production use, and that the static() helper works only in debug mode. The security overview advises size limits at the web server and a distinct top-level or second-level domain, not a subdomain, for uploaded content. The middleware reference says to set nosniff at the front-end server when it serves MEDIA_URL directly.Where MEDIA_ROOT and MEDIA_URL point, the domain and server that answer MEDIA_URL, any script handler on that path, and the request body limit.Configuration excerpts, and the Content-Type and X-Content-Type-Options headers on one uploaded test file.
Raw SQLA code search for .raw(, .extra(, RawSQL( and cursor.execute.The raw SQL guide says to escape every user-controlled parameter by using params, not to use string formatting or quote placeholders, and that no checking is done on SQL passed to raw(). The QuerySet reference calls extra() a last resort that Django is no longer fixing bugs in. RawSQL requires params.Each call by file and line, and how each value reaches the SQL: params with an unquoted placeholder, or string formatting or concatenation. Table, column and sort names built from input, listed separately.The list, with the reviewer and the date. The SQL injection guide covers fixing what it finds.
Two-user test: object detail viewsA staging environment you control, two ordinary test accounts, A and B, each owning test records, and the list of views that take a record id in the path or query string.Django creates add, change, delete and view permissions per model. The guide to customising authentication says the core has no implementation of object permissions, so checking for them returns False or an empty list, and that an authentication backend can return object-level permissions as appropriate. This page's reading: unless such a backend is in use, each view needs its own ownership check.For each view, signed in as B, request A's record, then request it with no session. Record the status code and whether any of A's data appears. GET requests only.URL, account, status code and a short response excerpt with personal details removed.
Two-user test: admin change pages and actionsA staging environment you control, with two staff test accounts on the same model: A with the change permission and B with only the view permission. If a get_queryset() override limits staff to their own objects, give each account its own records.has_view_permission() returns True for the change or view permission by default. The admin reference says object-level view permissions are not visibility filters and do not stop information about an object appearing elsewhere in the admin, including the change list, related field choices, autocomplete results and recent actions. Django's post of 3 November 2026 describes CVE-2026-113733, in which admin users with view but not change permission on a user model were shown the entire password hash under the conditions it gives.As B: which objects and which actions the change list offers, whether A's object opens by URL and whether its fields are read-only, and what related field choices and autocomplete show. Do not run an action or save a form.Screenshots with the account, model, URL and date.
Django version and security releasesThe output of django-admin version where production runs, the Supported Versions table on the djangoproject.com download page, the archive of security issues, and the django-announce list.The download page gives the end of mainstream and extended support for each series; extended support covers security fixes and data loss bugs. The security policy says release notices list only supported versions as affected, and that older versions may be affected without being investigated or patched.The installed version, the status the download page gives for its series with the date read, and each archive entry dated after that patch release, marked as applying to this project or not.The page URLs with the dates read, and who receives django-announce.

Area

Where to look

  1. manage.py check --deploy
    Where to look
    Run python manage.py check --deploy where the production settings load: on the production or staging server, or with --settings set to the production settings module. Also read SILENCED_SYSTEM_CHECKS.
    What the Django documentation says
    The django-admin reference says --deploy activates some additional checks that are only relevant in a deployment setting, and that development settings may not have many production settings. The system check reference says the security checks do not audit code and help perform a low-hanging-fruit checklist. --fail-level defaults to ERROR, and all of the --deploy security checks except security.E023 and security.E024 are warnings.
    What to record
    The exact command, the settings module it used, each message with its id, and each silenced id with the reason it is silenced.
    Evidence to keep
    The output pasted as printed, with the date, the environment and the Django version. No settings edited during the review to clear a warning.
  2. Settings module and DEBUG
    Where to look
    DJANGO_SETTINGS_MODULE in the environment of the production process, the settings file it names, and the line that sets DEBUG.
    What the Django documentation says
    Per the deployment checklist, debug must never be enabled in production: it leaks lots of information about the project, with source code excerpts, local variables, settings and the libraries in use among its examples. The settings reference notes that the settings.py startproject creates sets DEBUG = True. security.W018 reports DEBUG left on.
    What to record
    The module path, whether DEBUG is a literal or read from the environment, and its value in production.
    Evidence to keep
    File path and line number, and the security.W018 result from the first row.
  3. SECRET_KEY and SECRET_KEY_FALLBACKS
    Where to look
    First, a search of tracked settings files that reports only the file and line number of any line assigning a literal value, never the matched text. Then, for a key loaded from elsewhere, the settings line that loads it and the name of the environment variable, file path or secrets store entry it reads from, without opening that file or entry.
    What the Django documentation says
    The checklist asks for a large random value, kept secret, not used anywhere else and not committed to source control. The settings reference says a known key can lead to privilege escalation and remote code execution vulnerabilities, and that old keys come out of SECRET_KEY_FALLBACKS when you are ready to expire what they signed. security.W009 and security.W025 report short, low-variety or django-insecure- keys.
    What to record
    That each is set, where it is loaded from, who can read that place, any tracked file and line that assigns a literal value, and how many fallback keys there are.
    Evidence to keep
    Names, locations and people only. Never the key, and no command, shell or debug page that prints settings.
  4. ALLOWED_HOSTS and forwarded host headers
    Where to look
    ALLOWED_HOSTS and USE_X_FORWARDED_HOST in the production settings, and the default server or virtual host of the web server in front of Django.
    What the Django documentation says
    Per the checklist, once DEBUG = False a suitable value is required or Django does not work at all; with a wildcard, validating the Host header becomes your job unless you otherwise ensure you are not vulnerable to that category of attacks; and requests for incorrect hosts should get a static error page from the web server ahead of Django, or be ignored there, rather than being forwarded to Django. The settings reference says USE_X_FORWARDED_HOST should only be enabled if a proxy which sets the header is in use. The security.W020 message says only that ALLOWED_HOSTS must not be empty in deployment.
    What to record
    Each entry and the site it serves, any '*' or leading-period wildcard, the value of USE_X_FORWARDED_HOST, and the proxy that sets that header.
    Evidence to keep
    Settings and web server excerpts. The Host header injection guide covers testing how the site responds.
  5. HTTPS, proxy header and cookie flags
    Where to look
    SECURE_SSL_REDIRECT, SECURE_PROXY_SSL_HEADER, SESSION_COOKIE_SECURE, SESSION_COOKIE_HTTPONLY and CSRF_COOKIE_SECURE, plus the load balancer or proxy configuration.
    What the Django documentation says
    The checklist says any website which allows users to log in should enforce site-wide HTTPS, and to set CSRF_COOKIE_SECURE and SESSION_COOKIE_SECURE once HTTPS is set up. The settings reference says to set SECURE_PROXY_SSL_HEADER only if you control your proxy or can otherwise be sure that it sets or strips the header appropriately, and warns that modifying it can compromise your site's security. Checks: security.W008 and security.W010 to security.W016.
    What to record
    Each value, the layer that redirects HTTP to HTTPS, and, if SECURE_PROXY_SSL_HEADER is set, the header and the proxy that strips it from incoming requests.
    Evidence to keep
    Settings and proxy excerpts, and the Set-Cookie attributes seen in the browser's developer tools when a test account signs in.
  6. SecurityMiddleware and its headers
    Where to look
    MIDDLEWARE; SECURE_HSTS_SECONDS, SECURE_HSTS_INCLUDE_SUBDOMAINS, SECURE_HSTS_PRELOAD, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_REFERRER_POLICY and SECURE_CROSS_ORIGIN_OPENER_POLICY; and the response headers of one Django page and one static or uploaded file.
    What the Django documentation says
    Without the middleware, security.W001 says SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_REFERRER_POLICY, SECURE_CROSS_ORIGIN_OPENER_POLICY and SECURE_SSL_REDIRECT will have no effect. In the 6.1 settings reference, nosniff defaults to True and both policies to 'same-origin', while SECURE_HSTS_SECONDS defaults to 0. The middleware reference suggests the front-end server perform the same functions where the deployment allows, and warns that HSTS applies to the entire domain. Checks: security.W004 to security.W006, security.W021, security.W022, security.E023 and security.E024.
    What to record
    Whether and where SecurityMiddleware sits in MIDDLEWARE, each setting's value, and the headers each of the two responses actually carried.
    Evidence to keep
    Both sets of response headers, read in the browser's developer tools, with the URL and date.
  7. CSRF, clickjacking and CSP middleware
    Where to look
    The full MIDDLEWARE list in order, X_FRAME_OPTIONS, and SECURE_CSP and SECURE_CSP_REPORT_ONLY if present.
    What the Django documentation says
    security.W002 and security.W003 report XFrameOptionsMiddleware or CsrfViewMiddleware missing, and security.W019 reports XFrameOptionsMiddleware present with X_FRAME_OPTIONS set to something other than 'DENY', its default. ContentSecurityPolicyMiddleware, new in Django 6.0, sets CSP headers from SECURE_CSP and SECURE_CSP_REPORT_ONLY. The ordering notes put SecurityMiddleware near the top when the SSL redirect is on, and CsrfViewMiddleware before view middleware that assumes CSRF attacks have been dealt with.
    What to record
    The ordered list, which of XFrameOptionsMiddleware, CsrfViewMiddleware and ContentSecurityPolicyMiddleware are present, and the X_FRAME_OPTIONS and CSP settings.
    Evidence to keep
    Settings excerpt with the date.
  8. CSRF_TRUSTED_ORIGINS and exempt views
    Where to look
    CSRF_TRUSTED_ORIGINS in the production settings, and a code search for csrf_exempt.
    What the Django documentation says
    CSRF_TRUSTED_ORIGINS defaults to an empty list and supports subdomain wildcards such as https://*.example.com. The middleware checks the Origin header, if the browser provides one, against the current host and this list. The CSRF reference says subdomains that can set cookies for the whole domain can, with a corresponding token, circumvent the protection, and the security overview says to be very careful with marking views csrf_exempt unless it is absolutely necessary.
    What to record
    Each origin with the business or service that owns it and why it posts to this site, and each exempt view with its URL and the check that replaces CSRF protection, such as a webhook signature.
    Evidence to keep
    The list with file and line references, and the person who confirmed each reason.
  9. Admin site access and staff accounts
    Where to look
    The URLconf line that includes admin.site.urls, anything in front of that path such as an address restriction, and the user and group lists in the admin.
    What the Django documentation says
    The admin reference says its recommended use is an organisation's internal management tool, that login needs is_staff by default, and that has_permission() defaults to requiring both is_active and is_staff. The authentication guide says admin access is granted per type of object through the view, add, change and delete permissions.
    What to record
    The admin path, any restriction in front of it, every staff and superuser account matched to a named person, and each group's permissions per model.
    Evidence to keep
    A dated export or screenshot of the user and group lists, with personal details trimmed.
  10. Admin actions
    Where to look
    Each ModelAdmin's actions attribute, the action decorator's permissions argument, and site-wide actions added with AdminSite.add_action() or removed with AdminSite.disable_action().
    What the Django documentation says
    Django ships a "delete selected objects" action available to all models; it uses QuerySet.delete(), so model delete() methods are not called. The permissions argument limits who is offered an action. The admin does not automatically check object-level permissions for each selected object when executing an action; to limit which objects an action may modify on that basis, the reference says to perform those checks in the action itself.
    What to record
    One line per action: its model, its permissions, whether the code checks each object, and whether it updates or deletes in bulk.
    Evidence to keep
    Code references by file and line.
  11. User-uploaded media
    Where to look
    MEDIA_ROOT, MEDIA_URL and STATIC_ROOT, the web server or storage configuration for the media path, any static() line in urls.py, and the web server's request body limit.
    What the Django documentation says
    The checklist calls media untrusted and says to make sure the web server never attempts to interpret it. The static files guide says serving uploads with django.views.static.serve() is not suitable for production use, and that the static() helper works only in debug mode. The security overview advises size limits at the web server and a distinct top-level or second-level domain, not a subdomain, for uploaded content. The middleware reference says to set nosniff at the front-end server when it serves MEDIA_URL directly.
    What to record
    Where MEDIA_ROOT and MEDIA_URL point, the domain and server that answer MEDIA_URL, any script handler on that path, and the request body limit.
    Evidence to keep
    Configuration excerpts, and the Content-Type and X-Content-Type-Options headers on one uploaded test file.
  12. Raw SQL
    Where to look
    A code search for .raw(, .extra(, RawSQL( and cursor.execute.
    What the Django documentation says
    The raw SQL guide says to escape every user-controlled parameter by using params, not to use string formatting or quote placeholders, and that no checking is done on SQL passed to raw(). The QuerySet reference calls extra() a last resort that Django is no longer fixing bugs in. RawSQL requires params.
    What to record
    Each call by file and line, and how each value reaches the SQL: params with an unquoted placeholder, or string formatting or concatenation. Table, column and sort names built from input, listed separately.
    Evidence to keep
    The list, with the reviewer and the date. The SQL injection guide covers fixing what it finds.
  13. Two-user test: object detail views
    Where to look
    A staging environment you control, two ordinary test accounts, A and B, each owning test records, and the list of views that take a record id in the path or query string.
    What the Django documentation says
    Django creates add, change, delete and view permissions per model. The guide to customising authentication says the core has no implementation of object permissions, so checking for them returns False or an empty list, and that an authentication backend can return object-level permissions as appropriate. This page's reading: unless such a backend is in use, each view needs its own ownership check.
    What to record
    For each view, signed in as B, request A's record, then request it with no session. Record the status code and whether any of A's data appears. GET requests only.
    Evidence to keep
    URL, account, status code and a short response excerpt with personal details removed.
  14. Two-user test: admin change pages and actions
    Where to look
    A staging environment you control, with two staff test accounts on the same model: A with the change permission and B with only the view permission. If a get_queryset() override limits staff to their own objects, give each account its own records.
    What the Django documentation says
    has_view_permission() returns True for the change or view permission by default. The admin reference says object-level view permissions are not visibility filters and do not stop information about an object appearing elsewhere in the admin, including the change list, related field choices, autocomplete results and recent actions. Django's post of 3 November 2026 describes CVE-2026-113733, in which admin users with view but not change permission on a user model were shown the entire password hash under the conditions it gives.
    What to record
    As B: which objects and which actions the change list offers, whether A's object opens by URL and whether its fields are read-only, and what related field choices and autocomplete show. Do not run an action or save a form.
    Evidence to keep
    Screenshots with the account, model, URL and date.
  15. Django version and security releases
    Where to look
    The output of django-admin version where production runs, the Supported Versions table on the djangoproject.com download page, the archive of security issues, and the django-announce list.
    What the Django documentation says
    The download page gives the end of mainstream and extended support for each series; extended support covers security fixes and data loss bugs. The security policy says release notices list only supported versions as affected, and that older versions may be affected without being investigated or patched.
    What to record
    The installed version, the status the download page gives for its series with the date read, and each archive entry dated after that patch release, marked as applying to this project or not.
    Evidence to keep
    The page URLs with the dates read, and who receives django-announce.

Where Django sits in your application

A Django project runs your views, forms, templates and models inside the framework, which also supplies sessions, user authentication, an ORM that builds database queries, and an optional admin site.

Django's security overview calls it a general-purpose web application framework and says its defaults reflect this, so they will not be the best solution for every particular case.

In production, Django sits behind other software. Its deployment checklist says the runserver command is not designed for a production setting and points to production-ready WSGI and ASGI servers. It also asks the web server in front of Django to validate the host and never to interpret uploaded media.

The security middleware reference adds that, if the deployment allows, it is usually a good idea to have the front-end web server perform the middleware's work, so that requests Django does not serve, such as static media or user-uploaded files, get the same protections.

This guide's review of a Django project looks at the framework's own protections and whether the production settings switch them on, at the servers and storage around Django, and at what your own code does with the tools the framework provides.

The security overview says web security requires a multi-layered approach, and that securing a single vector does not make a site secure overall, nor does a single apparent weakness necessarily compromise the entire site.

This guide was written from the Django 6.1 documentation and the djangoproject.com download page, read on 14 November 2026, with Django's security policy and archive of security issues read the same day in the development version of the documentation. If your project runs another release, open the same pages for that release from the version switcher on each documentation page and compare the setting names and defaults.

Is Django secure? What its documentation covers and what it leaves to your project

This page gives no yes or no.

It sets out what Django's documentation says the framework handles and what it leaves to the project. The security overview describes these protections, with the limits it gives for each:

  • Templates escape the characters that represent a risk in HTML, which the overview says protects against the majority of cross-site scripting attacks. It warns about the is_safe attribute in custom template tags, the safe template tag, mark_safe and turning autoescape off, and notes that the built-in escaping is intended to protect HTML output.
  • CSRF protection that checks for a secret in each POST request. The overview describes it as protection against most types of CSRF attacks, providing you have enabled and used it where appropriate, and notes it can be disabled globally or for particular views.
  • Querysets built with query parameterisation, so a query's SQL is defined separately from its parameters, which the underlying database driver escapes.
  • Clickjacking protection through the X-Frame-Options middleware, which can be disabled on a per view basis.
  • Host header validation against the ALLOWED_HOSTS setting in get_host(). The overview says this validation only applies via get_host(), and that code reading the Host header directly from request.META bypasses it.

What the documentation leaves with the project

The same documentation leaves these with the people who build and run the project:

  • Raw SQL. The overview says raw queries and custom SQL should be used sparingly, with every parameter the user can control properly escaped, and asks for caution with extra() and RawSQL.
  • Login throttling. Django does not throttle requests to authenticate users, and the overview says you may consider deploying a Django plugin or web server module to throttle them.
  • CORS. Django does not include built-in support for CORS headers.
  • Uploaded files. The overview says no bulletproof technical solution exists at the framework level to safely validate all user-uploaded file content.
  • Who owns which record. Django's permission framework has a foundation for object permissions but no implementation for it in the core.
  • Production settings. Among the settings in Django's deployment checklist are ones that must be set properly for Django to provide the expected level of security and ones that are expected to be different in each environment.

Where Django's security policy draws the line

Django's security policy draws the same line from the other side. Among its criteria for whether a report needs a security release, it says exploits that fail to follow security best practices, such as failing to sanitise user input, do not require one, and neither do exploits that only affect local development, such as runserver.

This page's reading: a Django security release changes Django's own code, and leaves a view in your project that skips an ownership check exactly as it was.

In its list of additional security topics, the overview points readers to an outside list of common web application vulnerabilities and says that while Django has tools to address some of the issues, other issues must be accounted for in the design of your project. The evidence matrix on this page has rows on both sides of that division.

What manage.py check --deploy reports, and what it leaves out

Django's system check framework is a set of static checks for validating a project, and the check command runs it across the whole project.

The --deploy option activates additional checks that are only relevant in a deployment setting. Running it through manage.py does the same thing as django-admin, with DJANGO_SETTINGS_MODULE set to point at the project's settings.py file.

That last detail decides which settings the result describes. The django-admin reference says a local development settings module may not have many of your production settings, so you will probably want to point the command at a different settings module, through DJANGO_SETTINGS_MODULE or the --settings option, or run it directly on a production or staging deployment to verify that the correct settings are in use.

The deployment checklist says to run it against your production settings file. A clean run against development settings describes development.

With --deploy, the security checks look at whether SecurityMiddleware, the clickjacking middleware and the CSRF middleware are in MIDDLEWARE; the HSTS, nosniff, SSL redirect, referrer policy and cross-origin opener policy settings; the length, variety and django-insecure- prefix of SECRET_KEY and of each key in SECRET_KEY_FALLBACKS; the Secure and HttpOnly flags on the session cookie and the Secure flag on the CSRF cookie; DEBUG; X_FRAME_OPTIONS; and an empty ALLOWED_HOSTS. The matrix on this page names the check ids row by row.

The system check reference is plain about what the security checks are not. It says they do not audit code, do intrusion detection or do anything particularly complex, and that they instead help perform an automated, low-hanging-fruit checklist that can help improve a site's security. That is how this page treats them: a starting point that records configuration, not evidence about the application's code.

  • Silenced checks are not output to the console, as the SILENCED_SYSTEM_CHECKS entry in the settings reference says. The system check reference says some of the security checks may not be appropriate for a particular deployment, giving HTTP to HTTPS redirection done in a load balancer as its example, and says to use SILENCED_SYSTEM_CHECKS to silence unneeded checks. Record that list beside the output, with the reason for each entry.
  • Warnings do not change the exit status by default. Messages below ERROR are reported to the console, and the --fail-level option, which sets the level that makes the command exit with a non-zero status, defaults to ERROR. Apart from security.E023 and security.E024, which cover invalid referrer policy and cross-origin opener policy values, the security checks the reference lists for --deploy are warnings with ids starting security.W. This page's reading: a pipeline step that relies on the exit code passes with those warnings present unless --fail-level is set to WARNING or a lower level.

SECRET_KEY, DEBUG and ALLOWED_HOSTS in production

Start with SECRET_KEY.

The settings reference says Django uses it for cryptographic signing: for all sessions when any session backend other than the cache backend is in use or the default get_session_auth_hash() is used, for messages stored with CookieStorage or FallbackStorage, for every PasswordResetView token, and for any other signing that is not given a different key.

Its warning says running Django with a known SECRET_KEY defeats many of Django's security protections and can lead to privilege escalation and remote code execution vulnerabilities. Django refuses to start if it is not set.

The deployment checklist asks for a large random value that is kept secret, says the key used in production should not be used anywhere else, and says to avoid committing it to source control. Instead of hardcoding it in the settings module, it suggests loading it from an environment variable or from a file.

The check security.W009 reports a key with fewer than 50 characters, fewer than 5 unique characters, or the prefix django-insecure-, which it says indicates a key Django generated automatically, and security.W025 applies the same test to each value in SECRET_KEY_FALLBACKS.

For the matrix, record that the key is set, the name of the environment variable or the path of the file it is loaded from, who can read that place, and whether a settings file tracked in the repository assigns it a literal value, by file and line. Never copy the key into your notes, and do not run anything that prints settings values to find out.

Rotation is a separate decision. The settings reference describes setting a new SECRET_KEY, moving the previous value to the beginning of SECRET_KEY_FALLBACKS, and removing old values from the end of that list when you are ready to expire the sessions, password reset tokens and other values signed with them. It says that once a key is in neither setting, everything it signed is invalidated, and that secret keys are not used for user passwords, so rotation does not affect them.

Because rotation changes what the running site accepts, it belongs in a planned change rather than in a read-only review.

DEBUG and ALLOWED_HOSTS each have a guide of their own in this library, the security misconfiguration and Host header injection guides, so they get only a few sentences here. Django's checklist is direct about debug: never enable it in production, because it leaks lots of information about your project, among them excerpts of your source code, local variables, settings and the libraries used.

The settings reference notes that the settings.py file startproject creates sets DEBUG = True for convenience; security.W018 reports DEBUG left on.

For ALLOWED_HOSTS, the checklist warns that a suitable value is required once DEBUG is False, since without one Django does not work at all, and that a wildcard leaves you to validate the Host header yourself or otherwise ensure you are not vulnerable to that category of attacks.

The message for security.W020 says only that ALLOWED_HOSTS must not be empty in deployment. On that wording, a list holding a wildcard does not raise it.

Django security middleware: the headers it sets and where it stops

django.middleware.security.SecurityMiddleware groups several protections, each one independently enabled or disabled with a setting: SECURE_CONTENT_TYPE_NOSNIFF, SECURE_CROSS_ORIGIN_OPENER_POLICY, SECURE_HSTS_INCLUDE_SUBDOMAINS, SECURE_HSTS_PRELOAD, SECURE_HSTS_SECONDS, SECURE_REDIRECT_EXEMPT, SECURE_REFERRER_POLICY, SECURE_SSL_HOST and SECURE_SSL_REDIRECT.

If the middleware is missing from MIDDLEWARE, security.W001 warns that SECURE_HSTS_SECONDS, SECURE_CONTENT_TYPE_NOSNIFF, SECURE_REFERRER_POLICY, SECURE_CROSS_ORIGIN_OPENER_POLICY and SECURE_SSL_REDIRECT will have no effect.

The 6.1 settings reference gives the defaults. SECURE_CONTENT_TYPE_NOSNIFF is True, and SECURE_REFERRER_POLICY and SECURE_CROSS_ORIGIN_OPENER_POLICY are both 'same-origin', so with the middleware in place the nosniff, Referrer-Policy and Cross-Origin-Opener-Policy headers are added to responses that do not already have them. SECURE_HSTS_SECONDS defaults to 0 and SECURE_SSL_REDIRECT to False, so HSTS and the HTTPS redirect stay off until someone sets them.

HSTS deserves care before anyone changes it. The settings reference warns that setting it incorrectly can irreversibly (for some time) break your site. The middleware reference suggests starting with a small value such as 3600 seconds and raising it once you confirm every asset is served securely, says the policy applies to your entire domain rather than the URL of the response, and recommends SECURE_HSTS_INCLUDE_SUBDOMAINS only where all subdomains are served exclusively over HTTPS.

The matrix records the values in force; choosing new ones is a decision for whoever owns the domain.

Behind a load balancer or reverse proxy, Django may not be able to tell that a request arrived over HTTPS. SECURE_PROXY_SSL_HEADER names the header that tells it. The settings reference says to set it only if you control your proxy or can otherwise be sure that it sets or strips the header appropriately, lists conditions that must all be true first, including that the proxy strips the header from all incoming requests, and warns that modifying the setting can compromise your site's security. The security overview adds that failing to set it where necessary can result in CSRF vulnerabilities.

The middleware reference also says that, where the deployment allows, it is usually a good idea for the front-end web server to perform the SecurityMiddleware's functions, and it makes the same point about nosniff: if your MEDIA_URL is served directly by the front-end web server, the header belongs there.

This page's advice is to read the response headers of a page Django renders and of one static or uploaded file separately, and record both.

Clickjacking and Content Security Policy middleware

XFrameOptionsMiddleware provides clickjacking protection through the X-Frame-Options header, and X_FRAME_OPTIONS defaults to 'DENY'. security.W002 reports the middleware missing, and security.W019 reports it present with a value other than 'DENY'. ContentSecurityPolicyMiddleware is new in Django 6.0: it sets Content-Security-Policy from SECURE_CSP and Content-Security-Policy-Report-Only from SECURE_CSP_REPORT_ONLY.

The security overview advises against excluding specific paths or responses from CSP protection, because a vulnerability on an unprotected page may be leveraged to attack protected pages.

CSRF protection and CSRF_TRUSTED_ORIGINS

CsrfViewMiddleware checks every request that does not use GET, HEAD, OPTIONS or TRACE: a CSRF cookie must be present and the csrfmiddlewaretoken field present and correct, or the user gets a 403 error.

It also checks the Origin header, when the browser sends one, against the current host and the CSRF_TRUSTED_ORIGINS setting, and for HTTPS requests without an Origin header it performs strict referer checking. security.W003 reports the middleware missing from MIDDLEWARE. The CSRF guide in this library explains the attack and the defences in general; this section stays with Django's settings.

CSRF_TRUSTED_ORIGINS defaults to an empty list. Each entry is a trusted origin for unsafe requests such as POST, and an entry can cover subdomains, as in 'https://*.example.com'. Every entry widens what Django accepts, so the matrix asks for each one with the business or service that owns it and the reason it needs to post to this site.

A wildcard entry trusts every subdomain under it, including any run by another team or supplier. The CSRF reference adds a limitation of its own: subdomains within a site can set cookies for the whole domain and, with a corresponding token, circumvent the protection, and the only way to avoid this is to ensure subdomains are controlled by trusted users or are unable to set cookies.

The protection can also be switched off view by view. csrf_exempt marks a view as exempt from the middleware, and the security overview says to be very careful with it unless it is absolutely necessary. Search the code for csrf_exempt and list each exempt view with its reason, such as a webhook endpoint that checks a signature instead.

The CSRF reference also says the protection assumes validation of the Host header and that there are no cross-site scripting vulnerabilities on the site, and the middleware reference warns that, on a site served over HTTPS, completely disabling the Referer header will interfere with CSRF protection, suggesting same-origin referrers instead.

The admin site: who reaches it and what a staff user can see

The admin reads your models to provide an interface where trusted users manage content.

Django's admin reference says its recommended use is limited to an organisation's internal management tool, and that it is not intended for building your entire front end around. It answers at whatever URL your URLconf hooks it into, /admin/ by default. Logging in requires is_staff to be True by default, and AdminSite.has_permission() defaults to requiring both is_active and is_staff.

Inside the admin, permissions are granted per type of object. The authentication guide says viewing objects needs the view or change permission for that type, the add form needs add, the change list and change form need change, and deleting needs delete. ModelAdmin's has_view_permission(), has_add_permission(), has_change_permission() and has_delete_permission() let a project decide permissions for individual objects.

The admin reference attaches a note to the first of these: object-level view permissions are not visibility filters, and do not stop information about an object appearing elsewhere in the admin, including in the change list, related field choices, autocomplete results and recent actions.

To restrict that, it says to customise the querysets the relevant views and form fields use, and its get_queryset() example limits users who are not superusers to objects whose author is the logged-in user.

Actions need their own look. Django ships a "delete selected objects" action available to all models, and the actions reference warns that it uses QuerySet.delete(), so your model's delete() method will not be called. An action can be limited to users with given permissions through the permissions argument of the action decorator, and is then available to a user who passes at least one of those checks.

The reference then says the admin does not automatically check object-level permissions for each selected object when executing an action, and that to limit which objects an action may modify on that basis, you perform those checks in the action itself.

Actions can also be added site-wide with AdminSite.add_action(), and from Django 6.1 the location argument can place an action on the change form as well as the change list.

An advisory about view-only admin users

An advisory from November 2026 shows why a view-only staff account deserves its own test. Django's security release post of 3 November 2026 describes CVE-2026-113733: admin users with the view (but not change) permission to a user model were shown the entire password hash when that model was not AUTH_USER_MODEL, or when AUTH_USER_MODEL inherited its password field from a concrete parent model through multi-table inheritance.

The post gives it severity "low" according to the Django Security Policy. It announced Django 6.1.3, 6.0.10 and 5.2.19 for the issues it describes, and lists the patches for this issue on the main, 6.1 and 6.0 branches.

Read on 14 November 2026, Django's archive of security issues listed Django 6.1 and 6.0 against it; the archive is where later issues appear.

For the matrix, list every staff and superuser account against a named person, the groups and per-model permissions each holds, and every registered action with its permissions argument and whether its code checks each object. Then run the two-user admin row with two staff test accounts.

Object detail views: a model permission is not an ownership check

When django.contrib.auth is in INSTALLED_APPS, Django creates default add, change, delete and view permissions for each model defined in an installed application.

The permission_required decorator and PermissionRequiredMixin check whether the user holds every permission they name. The guide to customising authentication says Django's permission framework has a foundation for object permissions but no implementation for it in the core, which means that checking for object permissions will always return False or an empty list. An authentication backend receives the object being checked and can return object-level permissions as appropriate.

This page's reading of that for your own views: a detail view protected by a model permission, or by a login check alone, lets any user who passes that check open any record whose id they put in the URL, unless the view itself checks that the record belongs to that user, for example by fetching it through a query that already includes the owner or the tenant.

The admin's get_queryset() example shows the shape of such a query. The broken access control guide covers the general method; in the matrix it becomes one row covering every detail view.

The test needs two ordinary test accounts, A and B, each owning at least one test record, in a staging environment you control. Signed in as B, request the detail URL of A's record, then request the same URL with no session, and record the status code and whether any of A's data appears.

Use only GET requests that open a page, and submit no forms. Repeat for every view that takes an id in its path or query string, including downloads and exports.

User-uploaded media and how it is served

The deployment checklist says media files are uploaded by your users and are untrusted, and asks you to make sure your web server never attempts to interpret them: if a user uploads a .php file, the web server should not execute it.

MEDIA_ROOT is the filesystem path that holds user-uploaded files and must have a different value from STATIC_ROOT, and the MEDIA_URL entry in the settings reference warns that there are security risks if you are accepting uploaded content from untrusted users.

The static files guide describes serving uploads from MEDIA_ROOT with django.views.static.serve() during development, says this is not suitable for production use, and notes that the static() helper works only in debug mode. In production, MEDIA_URL is answered by something else: the front-end web server, a storage service, or a view of your own, such as one the middleware reference mentions that requires authorisation before a download. The headers on those files come from whichever of these answers.

The security overview lists further steps for uploaded content:

  • Limit uploads to a reasonable size in the web server configuration to prevent denial of service, rather than relying solely on DATA_UPLOAD_MAX_MEMORY_SIZE or FILE_UPLOAD_MAX_MEMORY_SIZE.
  • If you serve your own static files, make sure handlers that would execute static files as code, such as Apache's mod_php, are disabled.
  • Know that an HTML file with a valid PNG header can pass the Pillow verification Django uses for ImageField, and may then be displayed as HTML depending on the type and configuration of your web server.
  • Serve uploaded content from a distinct top-level or second-level domain, which prevents a class of attacks blocked by same-origin policy protections. The overview says serving it from a subdomain of your own domain is not sufficient.
  • Consider defining a list of allowable file extensions and configuring the web server to serve only those files.

What to record about media

The file upload security guide in this library covers validating and storing uploads in general. For the matrix, record where MEDIA_ROOT and MEDIA_URL point, which server or service answers MEDIA_URL and on which domain, whether any script handler applies to that path, the request body limit at the web server, and the Content-Type and X-Content-Type-Options headers on one uploaded test file.

Raw SQL review: raw(), extra(), RawSQL and the cursor

Querysets keep SQL and values apart, which is why the security overview says they are protected from SQL injection.

The raw SQL guide names the ways of performing raw SQL queries: RawSQL fragments inside ORM queries, Manager.raw() for queries that return model instances, and executing custom SQL directly through connection.cursor(). It asks you to explore the ORM before using any of them, and its warning says that every time you use raw SQL you should properly escape any parameters the user can control by using params.

Each route has a warning of its own:

  • raw(): no checking is done on the SQL statement passed in. Values go in the params argument, with %s placeholders in the query string for a list or %(key)s placeholders for a dictionary, and the guide says: "Do not use string formatting on raw queries or quote placeholders in your SQL strings!" It says string interpolation or a quoted placeholder puts you at risk of SQL injection.
  • cursor.execute(): to protect against SQL injection, you must not include quotes around the %s placeholders in the SQL string.
  • extra(): the QuerySet reference says to use it as a last resort. It calls extra() an old API Django aims to deprecate at some point in the future, says to use it only if a query cannot be expressed with other queryset methods, and says Django is no longer improving or fixing bugs for it. User-controlled parameters go through params, and placeholders must not be quoted.
  • RawSQL: the expressions reference says params is a required argument, to force you to acknowledge that you are not interpolating your SQL with user-provided data, and again that placeholders must not be quoted.

Running the review

As this page sets it out, a raw SQL review is a search and a list. Search the codebase for .raw(, .extra(, RawSQL( and cursor.execute, and list each call by file and line. For each, record how every value reaches the SQL: through params with an unquoted placeholder, or through an f-string, % formatting, .format() or concatenation.

Record separately any table, column or sort name built from request input; the SQL injection guide covers names like these, which need an allow-list rather than a parameter.

Django vulnerabilities: supported versions and security releases

The Django project's own pages answer whether a release still gets fixes and what has been fixed: the download page, the security policy and the archive of security issues.

The download page lists release series with the end of mainstream support and of extended support for each, and its footnotes define extended support as security fixes and data loss bugs. Read on 14 November 2026, it listed 5.2 LTS, 6.0 and 6.1 as supported, with extended support ending April 2028, April 2027 and December 2027 respectively, and listed 4.2 LTS under unsupported previous releases, which it says no longer receive security updates or bug fixes. Check the page itself for the series you run.

Django's security policy says the team gives official security support to the main development branch, the two most recent release series, and long-term support releases for a specified period. When it issues releases for security reasons, the notice lists affected versions drawn solely from supported releases; older versions may also be affected, but the team does not investigate them or issue patches for them.

The archive of security issues lists each fixed and disclosed issue with its date, a brief description, the CVE identifier if applicable and the affected versions, with the same caveat about versions whose security support had expired.

To hear about releases, the policy says the team notifies the django-announce list of the date and approximate time of an upcoming security release, and the severity of the issues, approximately one week before public disclosure, a gap it may shorten for an issue it believes is particularly time-sensitive.

On the day, it publishes a post on the Django blog describing each issue and its resolution, and sends a notice to django-announce and the oss-security list. It says the overwhelming majority of users should subscribe to django-announce rather than request detailed notifications.

The policy says severity is determined primarily by the attack type. Remote code execution and SQL injection are high; cross-site scripting, cross-site request forgery and broken authentication are moderate; denial of service, sensitive data exposure, broken session management, unvalidated redirects and issues requiring an uncommon configuration option are low, and the security team can adjust the level for an individual vulnerability.

For the matrix, record the Django version installed in production, which django-admin version prints, the status the download page gives for its series with the date you read it, and each archive entry dated after your installed patch release, marked as applying to your project or not.

Django security best practices drawn from its documentation

This list is this page's own summary, drawn from the Django pages above.

Each item is a decision for the project's developers, and the matrix records whether it is in place.

  • Run check --deploy against your production settings file, as the deployment checklist asks, or on a production or staging deployment, as the django-admin reference describes.
  • Consider loading SECRET_KEY from an environment variable or a file, as the checklist suggests, keep it out of source control, and use the production key nowhere else.
  • Keep DEBUG off in production and list your host names in ALLOWED_HOSTS.
  • Enforce HTTPS across the whole site where users log in, as the checklist asks, and set SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE once it is in place.
  • Keep SecurityMiddleware, CsrfViewMiddleware and XFrameOptionsMiddleware in MIDDLEWARE, and treat each csrf_exempt view as an exception that needs a reason.
  • Keep the admin for internal staff, restrict what each staff account sees through querysets, and check each object inside admin actions.
  • Give each of your own views an ownership check, such as a query that includes the owner or tenant, since the core does not implement object permissions.
  • Keep uploads away from anything that would interpret them, limit their size at the web server, and consider serving them from a distinct top-level or second-level domain.
  • Prefer the ORM, and pass every value to raw(), extra(), RawSQL and the cursor through params.
  • Consider login throttling through a Django plugin or web server module, since Django does not throttle authentication requests.
  • Subscribe to django-announce and check the download page for your release series.

How to fill in the deployment evidence matrix

Make one copy for each environment you deploy, production first, then staging if it can be reached from the internet.

Work down the rows in order: the first row's output shows which later rows need the most attention.

  • Every row reads a setting, a file, a list or a response. None changes a setting, saves an admin form, runs an admin action, rotates a key or sends traffic to a system you do not own.
  • Run python manage.py check --deploy where the production settings load: on the production or staging server, or with --settings pointing at the production settings module. Paste the output as it printed, with the date and the Django version. Do not edit settings during the review to clear a warning; note it, and fix it afterwards as a planned change.
  • Record names, never values. For SECRET_KEY, database passwords and API keys, write that each is set, where it is loaded from and who can read that place. Do not open the debug page, a shell or any command that prints settings to find out.
  • Create the test accounts for the two-user rows in staging: two ordinary users who each own test records, and two staff users, one with the change permission and one with only the view permission on the same model. Use invented data.
  • Use only page views and GET requests in the two-user rows. Where an admin action or form looks open to the wrong user, record what is offered and leave any confirmation to a planned test against test records.
  • Date every screenshot and export, and trim personal details before the matrix is shared outside the team.
  • Repeat the matrix after a Django upgrade, a change to settings or MIDDLEWARE, a new admin action, or a new person with staff access.

What the matrix cannot show

The matrix records configuration and samples access.

It shows whether the protections Django offers are switched on in production, what the servers around Django add, where raw SQL and exempt views live, and whether two accounts can reach each other's records through the views you tried. It cannot show what it did not look at: a template that marks user input safe, a view missing from your list, a business rule that lets a user approve their own refund, or a raw query whose parameters looked fine while its SQL was assembled somewhere else.

A clean check --deploy run is the narrowest part of the evidence. Django's own reference says the security checks do not audit code and help perform an automated, low-hanging-fruit checklist, and Django's security policy says exploits which fail to follow security best practices, such as failure to sanitise user input, do not require a security release.

Passing both the checks and the matrix tells you the rows you checked match what the documentation asks for; it is not evidence about the application's own logic.

It is also a snapshot. Settings, staff accounts and code change after the review, and the archive of security issues gains entries. Date each row, and treat a row older than the last deployment as unchecked.

Where a Clever Ops assessment fits

This guide is informational.

It describes no Django-specific service, and nothing on this page is a test of the Django framework itself. The matrix is for the people who build and run a Django project, using their own accounts in an environment they control.

If you want your own Django application tested, that happens inside a scoped web application penetration test, the Clever Ops service for custom web applications and their APIs. That scope asks you for two test accounts per role, each holding some sample records, so that access between people who share a role can be tried in both directions; where the application keeps customer organisations apart, it asks for accounts in two of them too.

No testing begins until each target's owner has signed an authorisation and the testing policy of your hosting provider has been checked.

A secure code review works from read-only access to your repository, with a written scope naming the parts it reads, such as the authorisation layer and the routes that return customer data.

Filling in the matrix first helps with writing that scope: it names the environments, staff accounts, exempt views and raw queries, and shows which settings production actually runs with. A Django application that Clever Ops built or hosts gets the same checks under the label of a security review rather than an independent test, and its report says who built the application and who hosts it.

Clever Ops does not offer emergency incident response or round-the-clock monitoring. Where you suspect a key or an account is already being misused, bring in an incident response specialist first.

Frequently asked questions

This page gives no verdict; it sets out what Django's documentation describes. Django's templates escape characters that represent a risk in HTML, its CSRF middleware checks a secret on unsafe requests, its querysets are built with query parameterisation, and get_host() validates the Host header against ALLOWED_HOSTS, while its deployment checklist includes settings that must be set properly for Django to provide the expected level of security. Its security policy says exploits which fail to follow security best practices, such as failure to sanitise user input, do not require a security release. This page's reading: whether those protections are in force on a given site depends on its settings and its own code, which the matrix records.

Not by itself. Django's system check reference says the security checks do not audit code or do anything particularly complex, and that they help perform an automated, low-hanging-fruit checklist. Because a local development settings module may not have many of your production settings, the django-admin reference says you will probably want to point the command at a different settings module, or run it on a production or staging deployment. Warnings do not change the exit status unless --fail-level is lowered from its default of ERROR, and checks listed in SILENCED_SYSTEM_CHECKS are not output to the console.

It adds headers and a redirect, each controlled by a setting: HSTS through SECURE_HSTS_SECONDS, with SECURE_HSTS_INCLUDE_SUBDOMAINS and SECURE_HSTS_PRELOAD adding directives, X-Content-Type-Options: nosniff, a Referrer-Policy, a Cross-Origin-Opener-Policy, and a permanent redirect from HTTP to HTTPS through SECURE_SSL_REDIRECT. In Django 6.1, nosniff is on by default and both policies default to 'same-origin', while HSTS and the redirect are off until set. Requests Django does not serve, such as static or uploaded files, do not pass through it, which is why the middleware reference suggests the front-end web server do the same work where the deployment allows.

Not in its core. Django's authentication documentation says the permission framework has a foundation for object permissions but no implementation for it in the core, so checking for object permissions always returns False or an empty list, and an authentication backend can return object-level permissions as appropriate. In the admin, ModelAdmin methods can decide permissions per object, but the actions reference says the admin does not automatically check object-level permissions for each selected object when it runs an action. This page's reading: your own views need their own ownership check, such as fetching records through a query that includes the owner or tenant, and the two-user rows in the matrix test for it.

Check the Supported Versions table on the djangoproject.com download page, which gives the end of mainstream and extended support for each release series; extended support covers security fixes and data loss bugs. Django's security policy says release notices list only supported versions as affected, and that older versions may be affected without being investigated or patched. The policy says django-announce is told the date of an upcoming security release approximately one week before public disclosure, a gap it may shorten for a particularly time-sensitive issue. The archive of security issues lists each issue fixed and disclosed, with its affected versions.

Django documents both with warnings rather than a ban. The raw SQL guide says to explore the ORM first, to pass every user-controlled value through params, and not to use string formatting or quote placeholders. The QuerySet reference calls extra() an old API Django aims to deprecate at some point in the future, to be used as a last resort, and says Django is no longer improving or fixing bugs for it. RawSQL requires a params argument so that you acknowledge you are not interpolating user-provided data into the SQL.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.