Skip to main content

Simple middleware for filtering requests by their source IP address

Project description

https://badge.fury.io/py/django-middlewall.svg https://travis-ci.org/jmz-b/django-middlewall.svg?branch=master https://codecov.io/gh/jmz-b/django-middlewall/branch/master/graph/badge.svg

Simple middleware for blocking requests by IP Address

Quickstart

Install Django Middlewall:

pip install django-middlewall

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'middlewall.apps.MiddlewallConfig',
    ...
)

Enable middleware components:

# enable both white and black listing

MIDDLEWARE = [
    'middlewall.middleware.BlacklistMiddleware',
    'middlewall.middleware.WhitelistMiddleware',
    ...
]

Define access lists in CIDR notation:

# only allow requests from these subnets

MIDDLEWALL_WHITELIST = ['192.0.2.0/24', '198.51.100.0/24']

# also block this specific address

MIDDLEWALL_BLACKLIST = ['192.0.2.1/32']

(optional) Define a custom function to get remote addresses from request objects:

# take advantage of the X_FORWARDED_FOR support in ipware

MIDDLEWALL_ADDRESS_GETTER = 'ipware.ip.get_ip'

Running Tests

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -e .[test]
(myenv) $ pip install tox
(myenv) $ tox

Credits

History

0.1.1 (2017-03-09)

  • First release.

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-middlewall-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

django_middlewall-0.1.1-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-middlewall-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django-middlewall-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d3bcb4f4e56cd65cc9be3ab14e9b0106a62a3b640d223309e119cc6547b9f57e
MD5 50e4adf7b2bbe3c40a65155cda784019
BLAKE2b-256 ea72c663e52050aed3d51e0996d13eaa2f5f0c713e25f7f265ee5d4e3248b968

See more details on using hashes here.

Provenance

File details

Details for the file django_middlewall-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_middlewall-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cbeede1c5dfa60431558705d5518188709c5e5d62607b531b0e945720837e80d
MD5 955ce2f2924deb91d3ab7a6ac4655d8e
BLAKE2b-256 35a3733794bbf3793f4a956cf672eb40f2542c4bc4b3ca6df46fa7531c11e40f

See more details on using hashes here.

Provenance

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