Skip to main content

A Django Middleware to enalbe 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 enalbe 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 ALLOW_CIDR_NETS setting:

ALLOW_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 ALLOW_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 ALLOW_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.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.2.0.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

django_allow_cidr-0.2.0-py2.py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 2 Python 3

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