--- id: django-allow-cidr version: "0.8.0" license: Apache Software License 2.0 license_treatment: permissive maintenance: aging --- # django-allow-cidr — A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS. License: permissive · Maintenance: aging · Downloads: 965.1K/mo ## 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 above — 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 pip install django-allow-cidr uv add django-allow-cidr 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: unspecified - Install friction: low - Maintenance: aging - Downloads: 965.1K/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags django cidr ip ranges, allowed hosts subnet validation, django middleware ip whitelist, cidr network django, ip range allowed hosts, django ip filtering, subnet-based host validation, django-middleware, network-security, cidr-validation [View on SkillFed](https://skillfed.io/packages/django-allow-cidr) · [View on PyPI](https://pypi.org/project/django-allow-cidr/)