Skip to main content
https://img.shields.io/github/workflow/status/adamchainz/django-permissions-policy/CI/main?style=for-the-badge https://img.shields.io/coveralls/github/adamchainz/django-permissions-policy/main?style=for-the-badge https://img.shields.io/pypi/v/django-permissions-policy.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app.

Requirements

Python 3.6 to 3.9 supported.

Django 2.2 to 3.2 supported.


Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Installation

Install with pip:

python -m pip install django-permissions-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_permissions_policy.PermissionsPolicyMiddleware',
  ...
]

The middleware will set the Permissions-Policy header.

The header will not be set until you configure the setting to set at least one policy, as below.

(For backwards compatibility, the middleware is also importable from the alias FeaturePolicyMiddleware.)

Setting

Change the PERMISSIONS_POLICY setting to configure the contents of the header.

The setting should be a dictionary laid out with:

  • Keys as the names of browser features - a full list is available on the W3 Spec repository. The MDN article is also worth reading.

  • Values as lists of strings, where each string is either an origin, e.g. 'https://example.com', or of the special values 'self' or '*'. If there is just one value, no containing list is necessary. To represent no origins being allowed, use an empty list.

    Note that in the header, domains are wrapped in double quotes - do not include these quotes within your Python string, as 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.featurePolicy.allowedFeatures() on Chrome.

For backwards compatibility with old configuration, the value 'none' is supported in lists, but ignored - it’s preferable to use the empty list instead. It doesn’t make sense to specify 'none' alongside other values.

Examples

Disable geolocation entirely, for the current origin and any iframes:

PERMISSIONS_POLICY = {
    "geolocation": [],
}

Allow autoplay from only the current origin and iframes from https://archive.org:

PERMISSIONS_POLICY = {
    "autoplay": ["self", "https://archive.org"],
}

Allow autoplay from all origins:

PERMISSIONS_POLICY = {
    "autoplay": "*",
}

Download files

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

Source Distribution

django-permissions-policy-4.0.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

django_permissions_policy-4.0.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file django-permissions-policy-4.0.0.tar.gz.

File metadata

  • Download URL: django-permissions-policy-4.0.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for django-permissions-policy-4.0.0.tar.gz
Algorithm Hash digest
SHA256 fc468017e4a6d98f91695b40d6754fe592c2cd25b1ed97a602d12400093aa144
MD5 042b5649de4f259d52ff79b476777446
BLAKE2b-256 688f8be4929a342fcf5f35f67e827666c9007298b326adeda057ef59b438217e

See more details on using hashes here.

File details

Details for the file django_permissions_policy-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_permissions_policy-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for django_permissions_policy-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e69d6432a8fa16654a4344b20fc98642604b6cf86ef43ead23dba51645bd839
MD5 67221f76b5a603454b634e031e32002b
BLAKE2b-256 b0dd3b35a307c2c3a10b2f340b9ebe68c59254c1b2372e932dad706b33d31247

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