Skip to main content

TODO

Project description

django_referer_csrf

This project has 2 goals:

  1. Simplifiy django's CSRF protection so that developers don't need to worry about the token
  2. Make it easier for view code to invoke CSRF protection dynamically

The token isn't needed

https://security.stackexchange.com/a/197269

On https sites, django's csrf protection requires that the request's referer header matches the request's host header. This check makes the entire CSRF token redundant. The token check provides no extra security on top of the referer check.

Django skips the referer check on non-https sites, which is somewhat advantageous (it means that users who configure their web browsers not submit a referer header can still submit forms).

Our validator actually looks for a valid origin header or referer header. Modern browsers follow the (newish) spec, which is to send an origin header with every request other than head/get. This means that if users have the referer header disabled, they can still pass our CSRF check.

Usage

  • pip install django_referer_csrf
  • in your MIDDLEWARE setting, replace django.middleware.csrf.CsrfViewMiddleware with django_referer_csrf.Middleware

With this middleware, you can still use Djangos's csrf_exempt decorators.

If you want to apply the CSRF protection based on dynamic conditions in view code, just check to see what the Middleware.process_view() does and replicate that.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_referer_csrf-0.2.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_referer_csrf-0.2.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file django_referer_csrf-0.2.0.tar.gz.

File metadata

  • Download URL: django_referer_csrf-0.2.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.10.1 urllib3/1.26.7 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for django_referer_csrf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0b2ddfec35dc03a3af8ad978ed1239752381644f51fbf2cbe20c9e823c9fcf11
MD5 6f5580ad147c31eb563983009de9008e
BLAKE2b-256 3355fa703513baa34b9e05f7626e6174d994abd30eb3216bb47f82ae8837cd55

See more details on using hashes here.

File details

Details for the file django_referer_csrf-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_referer_csrf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.10.1 urllib3/1.26.7 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for django_referer_csrf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac209172d56951aaf537745db99644e90ced4090ef45760462537e0846e1ac38
MD5 9b38b1ecaaaef1f8e211d5c77a2a8076
BLAKE2b-256 fa79395a33188802e01b313a5b0f071f4d311a6182f1580e2916e53ed7c99468

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page