A Traefik middleware plugin for detecting and blocking potential security threats based on URL patterns and IP tracking.
-
Threat Detection: Identifies common attack patterns including:
- WordPress admin panels (
/wp-admin,/wp-login.php) - Database administration interfaces (
/phpmyadmin,/adminer) - Common exploit paths (
/.env,/.git,/config) - Admin interfaces (
/admin,/administrator,/console)
- WordPress admin panels (
-
IP Tracking & Blocking: Tracks suspicious IPs and automatically bans them after multiple threat attempts
-
Prometheus Metrics: Exports metrics for monitoring:
traefik_threat_plugin_banned_ips_total: Total number of currently banned IP addressestraefik_threat_plugin_threat_attempts_total: Total number of threat attempts detected
-
Configurable: Customize threat patterns, ban duration, and attempt thresholds
Add the plugin to your Traefik static configuration:
experimental:
plugins:
traefik-threath-plugin:
moduleName: github.com/CangioUni/traefik-threath-plugin
version: v1.0.0[experimental.plugins.traefik-threath-plugin]
moduleName = "github.com/CangioUni/traefik-threath-plugin"
version = "v1.0.0"--experimental.plugins.traefik-threath-plugin.modulename=github.com/CangioUni/traefik-threath-plugin
--experimental.plugins.traefik-threath-plugin.version=v1.0.0http:
middlewares:
threat-detector:
plugin:
traefik-threath-plugin:
enabled: true
maxAttempts: 5
banDuration: 3600 # seconds (1 hour)
threatPatterns:
- "/wp-admin"
- "/wp-login.php"
- "/admin"
- "/phpmyadmin"
- "/.env"
- "/.git"
routers:
my-router:
rule: "Host(`example.com`)"
middlewares:
- threat-detector
service: my-service[http.middlewares.threat-detector.plugin.traefik-threath-plugin]
enabled = true
maxAttempts = 5
banDuration = 3600
threatPatterns = [
"/wp-admin",
"/wp-login.php",
"/admin",
"/phpmyadmin",
"/.env",
"/.git"
]
[http.routers.my-router]
rule = "Host(`example.com`)"
middlewares = ["threat-detector"]
service = "my-service"| Option | Type | Default | Description |
|---|---|---|---|
enabled |
bool | true |
Enable or disable the plugin |
maxAttempts |
int | 5 |
Maximum number of threat attempts before banning an IP |
banDuration |
int | 3600 |
Duration in seconds for which an IP is banned (default: 1 hour) |
threatPatterns |
[]string | (see below) | List of URL patterns to detect as threats |
If not specified, the plugin uses these default patterns:
/wp-admin/wp-login.php/wp-login/admin/administrator/phpmyadmin/pma/mysql/db/adminer/.env/config/backup/sftp-config.json/.git/console
The plugin exposes Prometheus metrics at the /metrics endpoint:
# HELP traefik_threat_plugin_banned_ips_total Total number of currently banned IP addresses
# TYPE traefik_threat_plugin_banned_ips_total gauge
traefik_threat_plugin_banned_ips_total 5
# HELP traefik_threat_plugin_threat_attempts_total Total number of threat attempts detected
# TYPE traefik_threat_plugin_threat_attempts_total counter
traefik_threat_plugin_threat_attempts_total 42
You can scrape these metrics with Prometheus:
scrape_configs:
- job_name: 'traefik'
static_configs:
- targets: ['traefik:8080']- Request Inspection: Each incoming request is checked against the configured threat patterns
- IP Tracking: When a threat is detected, the source IP is recorded
- Automatic Banning: After
maxAttemptsthreats from the same IP, subsequent requests are blocked with HTTP 403 - Ban Expiry: Bans automatically expire after
banDurationseconds - Cleanup: Expired bans are cleaned up automatically every minute
The plugin extracts client IPs from:
X-Forwarded-Forheader (uses the first IP)X-Real-IPheaderRemoteAddr(fallback)
This ensures accurate IP tracking even when behind proxies or load balancers.
Protect your application from common attacks:
http:
middlewares:
security:
plugin:
traefik-threath-plugin:
enabled: true
maxAttempts: 3 # More strict
banDuration: 7200 # 2 hours
threatPatterns:
- "/wp-admin"
- "/wp-login"
- "/.env"
- "/admin"
routers:
api:
rule: "Host(`api.example.com`)"
middlewares:
- security
service: api-servicego build -v .go test -v ./...go test -v -race ./...MIT
Contributions are welcome! Please open an issue or submit a pull request.