Skip to content

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

License

Notifications You must be signed in to change notification settings

alexmuller/django-allow-cidr

 
 

Repository files navigation

Django Allow CIDR

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 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:

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 88.2%
  • Makefile 11.8%