The usual CrowdSec + Traefik setup (CrowdSec with Traefik behind Cloudflare) works off logs: a request hits the container, Traefik writes a line to access.log, CrowdSec parses it and bans the IP. That covers brute force and scanners, but an SQL injection or CVE exploit fires on the first request — before the IP lands on the ban list.
AppSec puts inspection right in the request path:
log-based: request ──→ Traefik ──→ app ──→ access.log ──→ CrowdSec (ban after the fact)
with AppSec: request ──→ Traefik ──→ CrowdSec:7422 (WAF) ── ok ──→ app
└── attack ──→ HTTP 403
The Traefik plugin already speaks to AppSec — no separate WAF container needed.
Enable AppSec in CrowdSec and Traefik
- In
/opt/crowdsec/docker-compose.yaml, append two rule collections toCOLLECTIONS— one for known CVEs and one for generic web-attack signatures:
environment:
COLLECTIONS: "crowdsecurity/linux crowdsecurity/sshd crowdsecurity/base-http-scenarios crowdsecurity/http-cve crowdsecurity/traefik crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules"
- Create the acquisition source
/opt/crowdsec/data/config/acquis.d/appsec.yamlso CrowdSec listens on port7422inside the sharedproxyDocker network (no need to publish it on the host viaports:):
source: appsec
listen_addr: 0.0.0.0:7422
appsec_config: crowdsecurity/appsec-default
labels:
type: appsec
Restart the stack: cd /opt/crowdsec && sudo docker compose up -d.
- In Traefik’s dynamic config
/opt/traefik/data/dynamic/crowdsec.yml, enable AppSec on thecrowdsecmiddleware:
crowdsecAppsecEnabled: true
crowdsecAppsecHost: crowdsec:7422
crowdsecAppsecFailureBlock: true
crowdsecAppsecUnreachableBlock: false
crowdsecAppsecFailureBlock: true— block the request if AppSec returns an error.crowdsecAppsecUnreachableBlock: false— let traffic through if thecrowdseccontainer is restarting or down. Settingtrueis stricter, but any CrowdSec outage takes down every site using this middleware.
Traefik picks up edits under dynamic/ without a restart.
What to weigh before turning it on
- Every request hits
crowdsec:7422. In regularstreammode, the plugin keeps bans in memory and polls every 15 s. With AppSec on, every HTTP request adds a local call over the Docker network — latency stays in milliseconds, butcrowdseccontainer load rises; watch its memory if Compose caps it atmem_limit: 256M. - False positives.
crowdsecurity/appsec-generic-rulescan block normal POST requests carrying code snippets, SQL, or HTML (such as note editors and CMS admin panels). If a service handles that kind of input regularly, keep onlycrowdsecurity/appsec-virtual-patching— it targets specific CVEs with almost no false positives. - You still need log parsing. AppSec inspects single requests; slow brute force, 404 scanning, and SSH attacks are still caught by log-based scenarios and banned in nftables at the host level.
How to check
Confirm the AppSec component loaded its rules:
docker exec crowdsec cscli metrics show appsec
Send a test request matching a .env read signature to any service behind crowdsec@file:
curl -i "https://whoami.example.org/.env"
Traefik should return 403 Forbidden, and running cscli metrics show appsec again should show the hit in the blocked-requests counter.
If it doesn’t work
Enabled crowdsecAppsecEnabled: true in crowdsec.yml, yet requests to /.env still reach the app
- Cause
- The
acquis.d/appsec.yamlsource or AppSec collections are missing in CrowdSec, or the router doesn’t attach thecrowdsec@filemiddleware. WithcrowdsecAppsecUnreachableBlock: false, the plugin lets traffic through whenever port7422is unreachable. - Fix
- Run
docker exec crowdsec cscli metrics show appsec(a rule table should appear) and check Traefik logs for connection errors tocrowdsec:7422.
Restarting the crowdsec container makes sites behind Traefik return 500 or 403
- Cause
crowdsec.ymlsetscrowdsecAppsecUnreachableBlock: true: while CrowdSec restarts, port7422stops answering and the plugin blocks all traffic.- Fix
- Set
crowdsecAppsecUnreachableBlock: falseso a CrowdSec restart doesn’t take sites offline.
A legitimate user request (for instance, saving a note containing code or SQL) gets 403
- Cause
- A generic rule from
crowdsecurity/appsec-generic-rulesmatched the request body or query parameters. - Fix
- Check which rule fired via
docker exec crowdsec cscli metrics show appsecand the CrowdSec logs, then disable that rule or keep onlycrowdsecurity/appsec-virtual-patchingfor known CVEs.