Lesson 6 of 9 · 25m
WAF Configuration That Survives Production
Managed rules, custom rules, ordering, logging, and the operational discipline that keeps protection from becoming self-inflicted downtime.
A WAF is not a magic shield you turn on once. It is a policy engine in the request path, which means every false positive is now your outage. The craft is not writing clever expressions; it is deploying rules incrementally, measuring what they would do, and making sure the people on call can tell attack traffic from a broken regex.
Use layers in the right order
Cloudflare's managed rulesets cover broad vulnerability classes: OWASP-style injection, exposed credentials, common CMS exploits, and Cloudflare's own threat intel. Custom rules are for your application-specific policy. Rate limiting is a separate control with different semantics. Do not write one enormous custom rule that tries to be all three.
A practical rule looks like this:
Field expression:
(http.request.method eq "POST" and http.request.uri.path eq "/login"
and ip.src.country in {"CN" "RU"} and not cf.threat_score lt 10)
Action: Managed ChallengeReadability matters. Six months from now, the question will not be "is this clever?" but "why did we challenge Singapore?"
Start in log/simulate, then challenge, then block
The deployment ladder is non-negotiable for anything that can affect users:
- Log or simulate long enough to see real traffic.
- Managed Challenge for suspicious but uncertain traffic.
- Block only when false positives are understood and acceptable.
Challenge actions are often better than hard blocks at the edge. They preserve access for edge cases while raising attacker cost. Hard-blocking broad patterns like user-agent contains "python" mostly blocks uptime monitors, mobile WebViews, and your own integration tests.
Scope tightly and prefer positive boundaries
The safest custom rules are narrow:
http.request.uri.path eq "/api/graphql" and http.request.method eq "POST"The dangerous ones use huge negations and regexes copied from a blog post. Cloudflare's Rules language is intentionally structured — use fields, operators, and lists before regex. When regex is necessary, anchor it and test it against real request samples.
Logging is part of the control plane
If you cannot answer "which rule matched, with what ray ID, and what did the request look like?" you do not have a WAF; you have a superstition. Security Events, sampled logs, and cf-ray correlation are operational requirements. Keep rule names boring and descriptive because those names are what incident responders see.
Field notes
- Emergency rule edits during an attack should still go through a second pair of eyes. Self-inflicted WAF outages are common precisely because everyone is in a hurry.
- Exempt health checks and internal automation explicitly, then verify they cannot be abused as a bypass.
- Rule order matters: allow known-good automation first, challenge broad abuse second, block exploit signatures where appropriate.
- Review false positives with application owners. The WAF often exposes broken clients before it blocks attackers.
Was this lesson helpful?