djangodocs.org

309 sections across all versions Narrow to Django 6.0 (current) →

5.0

Internals Django Deprecation Timeline

The CSRF_COOKIE_MASKED transitional setting will be removed. The name argument of django.utils.functional.cached_property() will be removed. The opclasses argument of django.contrib.postgres.constraints.ExclusionConstraint will be removed. The undocumented ability to pass errors=None to SimpleTestCase.assertFormError() and assertFormsetError() will be removed. django.contrib.sessions.serializers.PickleSerializer will be removed.

6.0

django.security.*

Reference Logging Django logging extensionsLoggers

To silence a particular type of SuspiciousOperation, you can override that specific logger following this example: Other django.security loggers not based on SuspiciousOperation are: django.security.csrf: For CSRF failures.

4.2 5.0 5.1 5.2 6.0

Referrer Policy

Reference Middleware Available middlewareSecurity middleware

WARNING: When your site is served via HTTPS, Django’s CSRF protection system requires the Referer header to be present, so > completely disabling the Referer header will interfere with CSRF > protection.

4.2 5.0 5.1 5.2 6.0

FileField

Reference Model field reference Field types

Don’t allow that. Also note that even an uploaded HTML file, since it can be executed by the browser (though not by the server), can pose security threats that are equivalent to XSS or CSRF attacks.

4.2 5.0 5.1 5.2 6.0

The per-view cache

Topic guide Django’s cache framework

If cache variation depends on response > middleware, ensure it runs before the response is cached. For example, when > caching views containing CSRF-protected forms, follow > Using CSRF protection with caching to ensure the Vary header is set first.

6.0

process_view()

Topic guide Middleware Other middleware hooks

The CsrfViewMiddleware class can be > considered an exception, as it provides the > csrf_exempt() and > csrf_protect() decorators which allow > views to explicitly control at what point the CSRF validation should occur.

4.2 5.0 5.1 5.2 6.0

Using Django

Topic guide

… in a view function Security in Django Always sanitize user input Cross site scripting (XSS) protection Cross site request forgery (CSRF) protection SQL injection protection Clickjacking protection SSL/HTTPS Host header validation Referrer policy Cross-origin opener policy Session security User-uploaded content …

4.2 5.0 5.1 5.2 6.0

Topic guide Testing tools The test client

By default, the test client will disable any CSRF checks performed by your site. If, for some reason, you want the test client to perform CSRF checks, you can create an instance of the test client that enforces CSRF checks.

4.2 5.0 5.1 5.2 6.0

5.0

Internals Django Deprecation Timeline

The CSRF_COOKIE_MASKED transitional setting will be removed. The name argument of django.utils.functional.cached_property() will be removed. The opclasses argument of django.contrib.postgres.constraints.ExclusionConstraint will be removed. The undocumented ability to pass errors=None to SimpleTestCase.assertFormError() and assertFormsetError() will be removed. django.contrib.sessions.serializers.PickleSerializer will be removed.

5.2

5.0

Internals Django Deprecation Timeline

The CSRF_COOKIE_MASKED transitional setting will be removed. The name argument of django.utils.functional.cached_property() will be removed. The opclasses argument of django.contrib.postgres.constraints.ExclusionConstraint will be removed. The undocumented ability to pass errors=None to SimpleTestCase.assertFormError() and assertFormsetError() will be removed. django.contrib.sessions.serializers.PickleSerializer will be removed.

5.0 5.1

5.0

Internals Django Deprecation Timeline

The CSRF_COOKIE_MASKED transitional setting will be removed. The name argument of django.utils.functional.cached_property() will be removed. The opclasses argument of django.contrib.postgres.constraints.ExclusionConstraint will be removed. The undocumented ability to pass errors=None to SimpleTestCase.assertFormError() and assertFormsetError() will be removed. django.contrib.sessions.serializers.PickleSerializer will be removed.

4.2

1.7

Internals Django Deprecation Timeline

The undocumented check_for_test_cookie method in AuthenticationForm will be removed following an accelerated deprecation. Users subclassing this form should remove calls to this method, and instead ensure that their auth related views are CSRF protected, which ensures that cookies are enabled.

4.2

… Using Paginator in a view function Security in Django Always sanitize user input Cross-site scripting (XSS) protection Cross-site request forgery (CSRF) protection SQL injection protection Clickjacking protection SSL/HTTPS Host header validation Referrer policy Cross-origin opener policy Cross-origin resource sharing (CORS) …

dev

D

Index

… django.middleware - module - django.middleware.cache - module - django.middleware.clickjacking - module - django.middleware.common - module - django.middleware.csp - module - django.middleware.csrf - module - django.middleware.gzip - module - django.middleware.http - module - django.middleware.locale - module - django.middleware.security - module - …

M

Index

… django.forms.formsets - django.forms.models - django.forms.renderers - django.forms.widgets - django.http - django.middleware - django.middleware.cache - django.middleware.clickjacking - django.middleware.common - django.middleware.csp - django.middleware.csrf - django.middleware.gzip - django.middleware.http - django.middleware.locale - django.middleware.security - django.shortcuts - django.tasks - django.tasks.backends.base - django.tasks.backends.dummy - django.tasks.backends.immediate - …

S

Index

… CACHES - CACHES-BACKEND - CACHES-KEY_FUNCTION - CACHES-KEY_PREFIX - CACHES-LOCATION - CACHES-OPTIONS - CACHES-TIMEOUT - CACHES-VERSION - CONN_HEALTH_CHECKS - CONN_MAX_AGE - CSRF_COOKIE_AGE - CSRF_COOKIE_DOMAIN - CSRF_COOKIE_HTTPONLY - CSRF_COOKIE_NAME - CSRF_COOKIE_PATH - CSRF_COOKIE_SAMESITE - CSRF_COOKIE_SECURE - CSRF_FAILURE_VIEW - CSRF_HEADER_NAME - CSRF_TRUSTED_ORIGINS - …

Python Module Index

| | | django.middleware.csp | Middleware for Content Security Policy headers | | | django.middleware.csrf | Protects against Cross Site Request Forgeries | | | django.middleware.gzip | Middleware to serve GZipped content for performance.