IP Filtering
CIDR-based IP allow and block rules to control access to your FastCMS instance. Supports IPv4, IPv6, expiring rules, and admin-managed entries.
IP Filtering
FastCMS supports CIDR-based IP filtering to allow or block access from specific IP addresses or ranges. Rules are stored in the database and evaluated on every request.
Enable IP Filtering
IP_FILTER_ENABLED=trueWhen disabled (default), all IP filtering middleware is bypassed completely.
How It Works
- Block rules — deny the request with
403 Forbidden - Allow rules — used for documentation/allowlist purposes (does not bypass block rules)
- Rules support CIDR notation:
192.168.1.0/24,10.0.0.1,2001:db8::/32 - Rules can have an optional expiry date — expired rules are ignored automatically
- Block rules take precedence
Exempt paths (never filtered): /health, /api/v1/health
API Endpoints
All endpoints require admin authentication.
List Rules
GET /api/v1/ip-rules
Authorization: Bearer ADMIN_TOKENQuery Parameters:
| Parameter | Description |
|---|---|
rule_type | Filter by allow or block |
skip | Pagination offset |
limit | Max results (default 100) |
Create a Rule
POST /api/v1/ip-rules
Authorization: Bearer ADMIN_TOKEN
Content-Type: application/jsonBlock a single IP:
{
"cidr": "203.0.113.5",
"rule_type": "block",
"reason": "Repeated abuse",
"expires_at": null
}Block a CIDR range with expiry:
{
"cidr": "198.51.100.0/24",
"rule_type": "block",
"reason": "Suspicious range",
"expires_at": "2026-06-01T00:00:00Z"
}Allow a trusted range:
{
"cidr": "10.0.0.0/8",
"rule_type": "allow",
"reason": "Internal network"
}Delete a Rule
DELETE /api/v1/ip-rules/{rule_id}
Authorization: Bearer ADMIN_TOKENBlocked Request Response
HTTP/1.1 403 Forbidden{
"detail": "Access denied: Repeated abuse"
}CIDR Notation Reference
| CIDR | Covers |
|---|---|
1.2.3.4 | Single IP |
1.2.3.0/24 | 256 IPs (1.2.3.0–1.2.3.255) |
1.2.0.0/16 | 65,536 IPs |
10.0.0.0/8 | All 10.x.x.x |
0.0.0.0/0 | All IPv4 (use with caution) |
X-Forwarded-For Support
When running behind a reverse proxy or load balancer, FastCMS reads the client IP from headers in this order:
X-Forwarded-For(first IP in list)X-Real-IP- Direct connection IP
Ensure your proxy sets these headers correctly.
Audit Integration
All blocked requests are logged to the audit system:
GET /api/v1/audit?event_type=security&event_action=ip_blocked
Authorization: Bearer ADMIN_TOKEN