skillfed

django-allow-cidr

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

django-allow-cidr v0.8.0 965.1K downloads/30d#4,624 on PyPI111
Permissive license Apache Software License 2.0 AGING released

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

uv

uv add django-allow-cidr

poetry

poetry add django-allow-cidr

Installing 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

Development Status :: 4 - BetaFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.1Framework :: Django :: 5.2Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9

Tags

django cidr ip rangesallowed hosts subnet validationdjango middleware ip whitelistcidr network djangoip range allowed hostsdjango ip filteringsubnet-based host validation
django-middlewarenetwork-securitycidr-validation

More WWW/HTTP packages