TODO
Project description
django_referer_csrf
This project has 2 goals:
- Simplifiy django's CSRF protection so that developers don't need to worry about the token
- 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, replacedjango.middleware.csrf.CsrfViewMiddleware
withdjango_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_referer_csrf-0.0.0.tar.gz
.
File metadata
- Download URL: django_referer_csrf-0.0.0.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.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d31c02792bc4f09e3707405de9fb2d263d6b237afba78347ba73151f5c71a821 |
|
MD5 | 9695fa54005318f0f63ae2039ced50be |
|
BLAKE2b-256 | bd9e8e67dac598a3e281680ab1ee07a4a2dca49fe51408a3c385a310dae035df |
File details
Details for the file django_referer_csrf-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_referer_csrf-0.0.0-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.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ae3ddfb4c86b4756df8009cab658eca57ec71a3ba8b0b914bf75070ab215e03 |
|
MD5 | fef018bcd04d03aa7b5729b5888b4079 |
|
BLAKE2b-256 | 8a2efa6d808aa75ce33057c857eda0e5e43d2688bbef8d4399507c639bc391b7 |