Skip to main content

A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.

Project description

https://badge.fury.io/py/django-allow-cidr.svg https://github.com/mozmeao/django-allow-cidr/actions/workflows/ci.yml/badge.svg

A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.

Quickstart

Install Django Allow CIDR:

pip install django-allow-cidr

Add the Middleware to your MIDDLEWARE settings. It should be the first in the list:

MIDDLEWARE = (
    'allow_cidr.middleware.AllowCIDRMiddleware',
    ...
)

Add the ALLOWED_CIDR_NETS setting:

ALLOWED_CIDR_NETS = ['192.168.1.0/24']

Profit!

Features

  • The normal ALLOWED_HOSTS values will also work as intended. This Middleware is intended to augment, not replace, the normal Django function.

  • If you do define ALLOWED_CIDR_NETS and it has values, the middleware will capture what you have in ALLOWED_HOSTS, set ALLOWED_HOSTS to [‘*’] and take over validation of host headers.

  • The ALLOWED_CIDR_NETS values can be any valid network definition for the netaddr package.

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

History

0.4.0 (2022-02-22)

  • Drop Django support for non-LTS and non-latest Django (so, removing 1.x, 2.0, 2.1, 3.0, 3.1)

  • Drop support for older Python releases (2.x, 3.5)

  • Add Django 4.0 to tox’s test matrix

  • Add Python 3.7 through 3.10 to tox’s test matrix; 3.6 to 3.10 are now the only tested versions

  • Switch CI to Github Actions

0.3.1 (2018-07-31)

  • Fix issue #6: Accept passed in get_response function for Middleware in Django >= 1.10.

  • Publish updated docs that fix the ALLOWED_CIDR_NETS typo.

0.3.0 (2018-02-21)

  • Disable middleware if ALLOWED_HOSTS is set to [‘*’].

0.2.0 (2018-02-21)

  • Handle host names with ports (Thanks Giorgos!).

0.1.0 (2018-02-16)

  • First release on PyPI.

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-allow-cidr-0.4.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

django_allow_cidr-0.4.0-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-allow-cidr-0.4.0.tar.gz.

File metadata

  • Download URL: django-allow-cidr-0.4.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for django-allow-cidr-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9f6c3ffbad47f0e722fb208bc857e10153054d6ef02c462047fa4815671adc57
MD5 ba9433755c9816273418a53140641b93
BLAKE2b-256 19a1d6cc2ece79b7c9ffc8217bcb753a04541ab66b69adc1f14153091003a346

See more details on using hashes here.

File details

Details for the file django_allow_cidr-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_allow_cidr-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for django_allow_cidr-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b9758a7c9626fa2b00735ce0e3f45b46471a2bb7c21edc7cee1d52ec04e63788
MD5 a5e17dd0d038de63115f748da901a376
BLAKE2b-256 e4c8ed1d459bad82843020174b71de21c1e1ce8031ad027de999fe50131b8296

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