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.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_referer_csrf-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10

File hashes

Hashes for django_referer_csrf-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b2a4961c1a605ce25d9ece79a0b3c280ca3e923eebc9a6b2b68e84dfd5eeafbc
MD5 1c168a1d1d58dc70fce89f9b10b338b2
BLAKE2b-256 d353ee8373a7addc460d469c14cc46d7c168db7e0202be92dcf03aa1bb9afe2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_referer_csrf-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10

File hashes

Hashes for django_referer_csrf-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f8dbb813829d086581268f05fb58a67522de1a2a8109fdfba8f6bcfb7a5d344
MD5 62c31faa5be11a6170564ef4d80ef48d
BLAKE2b-256 7eb5b678062681a86340537d0c9635843927e3003de0c2993ed0228a48283ee3

See more details on using hashes here.

Supported by

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