django-allow-cidr
A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS.
What it is and what it does
django-allow-cidr is a Django middleware that augments the standard ALLOWED_HOSTS validation by adding support for CIDR network ranges. Instead of listing individual IP addresses or hostnames, you define subnets using standard CIDR notation (e.g., 192.168.1.0/24) in an ALLOWED_CIDR_NETS setting, and the middleware validates incoming Host headers against both the traditional ALLOWED_HOSTS and your CIDR ranges. When ALLOWED_CIDR_NETS is configured, the middleware takes over Host header validation entirely, replacing ALLOWED_HOSTS with ['*'] internally to prevent Django's default validation from interfering.
The package uses Python's built-in ipaddress library for network validation, supports both IPv4 and IPv6, and works alongside normal ALLOWED_HOSTS entries. It is designed as a drop-in middleware that requires minimal configuration—just add it to the top of your MIDDLEWARE list and define your CIDR ranges.
Use it for:
- Whitelist entire office or data-center subnets without listing every individual IP address
- Allow requests from cloud provider IP ranges or load-balancer subnets in production environments
- Restrict API access to specific network segments in multi-tenant or internal-only deployments
- Simplify Host header validation when you control the network topology but not individual client IPs
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A Django middleware that extends ALLOWED_HOSTS validation to support CIDR IP ranges, allowing you to whitelist entire subnets instead of individual IP addresses.
Yes, if you need to validate Host headers against CIDR ranges. The middleware is straightforward, has no known vulnerabilities, carries a permissive license, and integrates cleanly with Django's standard security model. The aging maintenance status is not a blocker—the package is stable, recently updated for current Django and Python versions, and solves a specific problem without heavy dependencies.
Install
django-allow-cidr on PyPI
pip
pip install django-allow-cidruv
uv add django-allow-cidrpoetry
poetry add django-allow-cidrInstalling django-allow-cidr
Before you install
Low friction installation with a single pure-Python dependency on Django. The package is aging (last release 493 days ago) but remains actively maintained on the repository, with recent CI updates for Django 5.2 and Python 3.13 support.
License in practice
Licensed under Apache Software License 2.0, a permissive license that allows commercial use, modification, and distribution with minimal restrictions.
Quickstart
pip install django-allow-cidr
# In settings.py
MIDDLEWARE = (
'allow_cidr.middleware.AllowCIDRMiddleware',
...
)
ALLOWED_CIDR_NETS = ['192.168.1.0/24']
Verify before relying
- Whether the middleware correctly handles edge cases like IPv6 addresses with zone identifiers or non-standard CIDR notation
- Performance impact when ALLOWED_CIDR_NETS contains a large number of networks
Package facts
| License | Apache Software License 2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — Django |
| Maintenance | aging — 493 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 965,054/month — #4,624 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_allow_cidr-0.8.0-py2.py3-none-any.whl
Keywords: django-allow-cidr
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
django-ebhealthcheckAutomatically adds an Elastic Beanstalk…
permissive · top 15,000 on PyPI
django-netfieldsProvides Django model fields for PostgreSQL…
permissive · top 15,000 on PyPI
netaddrRepresents and manipulates IPv4, IPv6, MAC…
permissive · top 5,000 on PyPI
iptoolsProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
django-xffDjango middleware that extracts the real client…
permissive · top 15,000 on PyPI
ipaddrProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
django-localflavorProvides country-specific form fields,…
permissive · top 5,000 on PyPI
cidr-trieStores and queries CIDR IP address blocks (IPv4…
permissive · top 15,000 on PyPI
ipaddressProvides IPv4 and IPv6 address manipulation for…
permissive · top 5,000 on PyPI
django-axesdjango-axes tracks failed login attempts to…
permissive · top 5,000 on PyPI