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://travis-ci.org/mozmeao/django-allow-cidr.svg?branch=master

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_CLASSES (for Django < 1.10) or 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.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.3.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

django_allow_cidr-0.3.1-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-allow-cidr-0.3.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for django-allow-cidr-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d9a3b22c14e91c26ddd010c278ddf7e2c69a5421c862a3a3cd448ae57fd833e8
MD5 d6bd11e6694149a1516a0989c32c92aa
BLAKE2b-256 af621067e4c4b35098e56e31393a320c224289fb31110d02be2dba9fe1f91589

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_allow_cidr-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3

File hashes

Hashes for django_allow_cidr-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e8708c0511a78b80d9b74f718ee46685a1425e6d3520143bd00c773fdca56cc7
MD5 25bd4aef028ddb462e7ce7af6e9abed0
BLAKE2b-256 19284030e333a2100b73962fb9ff7fac85567168c45aa01f3df76e8f729c8924

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