Set the draft security HTTP header Feature-Policy on your Django app.
Project description
django-feature-policy
Set the draft security HTTP header Feature-Policy on your Django app.
Requirements
Tested with all combinations of:
Python: 3.6
Django: 2.0, 2.1
Installation
Install with pip:
pip install django-feature-policy
Then add the middleware, best after Django’s SecurityMiddleware as it does similar addition of security headers that you’ll want on every response:
MIDDLEWARE = [
...
'django.middleware.security.SecurityMiddleware',
'django_feature_policy.FeaturePolicyMiddleware',
...
]
By default no header will be set, configure the setting as below.
Setting
Change the FEATURE_POLICY setting to configure what Feature-Policy header gets set.
This should be a dictionary laid out with:
Keys as the names of browser features - a full list is available on the MDN article.
Values as lists of strings, where each string is either an origin, e.g. 'https://example.com', or of the special values 'self', 'none', or '*'. If there is just one value, no containing list is necessary. Note that in the header, special values like 'none' include single quotes around them - do not include these quotes in your Python string, they will be added by the middleware.
If the keys or values are invalid, ImproperlyConfigured will be raised at instantiation time, or when processing a response. The current feature list is pulled from the JavaScript API with document.policy.allowedFeatures() on the latest Chrome build.
Examples
Disable geolocation from running in the current page and any iframe:
FEATURE_POLICY = {
'geolocation': 'none',
}
Allow autoplay from the current origin and iframes from https://archive.org:
FEATURE_POLICY = {
'autoplay': ['self', 'https://archive.org'],
}
History
Pending release
1.0.1 (2019-01-02)
Support for new ‘lazyload’ feature, per https://www.chromestatus.com/feature/5641405942726656.
1.0.0 (2018-10-24)
First release, supporting adding the header with a middleware.
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
Hashes for django-feature-policy-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 171fd6a48afa232617dfaa64239f03c4808c4eb617a2d4f995c5d1e564ec6803 |
|
MD5 | ac551fe050ab598f7b350271315a41e7 |
|
BLAKE2b-256 | 488326ac104d092be9754ac24a34b0072dfa775c74b36a6db55413a7678b4bbd |
Hashes for django_feature_policy-1.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b51264198777ebd4c9ed7489d6c2aa513ddef000866aef37bbb76cb55bae8835 |
|
MD5 | 9d400ec7e04cf6eeb1ae4ff79405c28e |
|
BLAKE2b-256 | 56e5927dce9b349b1bfe8f5e328871d971979c94105d7766ab3c0c75787bfd56 |