| title | Dynamic IP Blocklist |
|---|---|
| sidebar_position | 12 |
The dynamic IP blocklist subscribes to external threat intelligence feeds and blocks or logs requests from listed IP addresses. It supports both static IP/CIDR entries and auto-refreshing feeds in text or JSON format.
IP blocklist can be configured globally and per-route.
ip_blocklist:
enabled: true
static: # always-blocked IPs/CIDRs
- "203.0.113.0/24"
- "198.51.100.50"
action: block # "block" (default) or "log"
feeds:
- url: "https://feeds.example.com/bad-ips.txt"
refresh_interval: 5m # default 5m
format: text # "text" (default) or "json"
- url: "https://feeds.example.com/threat-ips.json"
refresh_interval: 10m
format: jsonroutes:
- id: api
path: /api
ip_blocklist:
enabled: true
static:
- "192.0.2.0/24"
action: block
feeds:
- url: "https://feeds.example.com/api-blocklist.txt"
refresh_interval: 5m
format: text- On startup, static entries are parsed into IP networks
- Background goroutines fetch each feed at the configured
refresh_interval - On each request, the client IP (from
X-Forwarded-For/ trusted proxy extraction) is checked against all static entries and feed entries - If matched and
action: block, the request is rejected with 403 Forbidden - If matched and
action: log, the request proceeds but a warning is logged
One IP or CIDR per line. Lines starting with # are treated as comments and skipped. Empty lines are ignored.
# Threat feed - updated daily
203.0.113.5
198.51.100.0/24
192.0.2.10
A JSON array of IP/CIDR strings:
["203.0.113.5", "198.51.100.0/24", "192.0.2.10"]When both global and per-route configs are enabled, they are merged:
- Static entries from both configs are combined (union)
- Feeds from both configs are combined
- Per-route
actionoverrides the global action
IP blocklist runs at step 2.85 in the middleware chain — after bot detection (2.8) and before CORS (3). The global blocklist wraps the per-route blocklist, so both are checked.
Returns blocklist status for all routes.
curl http://localhost:8081/ip-blocklistResponse (200 OK):
{
"api": {
"enabled": true,
"action": "block",
"static_entries": 3,
"feed_count": 2,
"total_blocked_ips": 1250,
"blocked_requests": 42
}
}Forces an immediate refresh of all feeds (global and per-route).
curl -X POST http://localhost:8081/ip-blocklist/refreshResponse (200 OK):
{
"status": "ok",
"refreshed": 3
}actionmust be"block"or"log"staticentries must be valid IPs or CIDRs- Feed
urlis required for each feed entry - Feed
formatmust be"text"or"json" - Feed
refresh_intervalmust be >= 1s when specified