Tuning Cloudflare WAF Rules Without Breaking Your Application
The most common WAF failure mode is not getting bypassed — it is getting disabled because it broke something. Systematic tuning prevents this. Here is how to do it without guesswork.
Why default managed rulesets cause false positives
Cloudflare's managed WAF rulesets — including the Cloudflare Managed Ruleset and the OWASP Core Rule Set — are designed to work across millions of different applications. They are conservative by default, which means they will catch a wide range of attack patterns but will also block legitimate traffic that happens to match those patterns.
The OWASP Core Rule Set uses a scoring model: each matching rule adds to the request's anomaly score, and the request is blocked when that score exceeds a threshold. At paranoia level 1 (the default), the threshold is relatively conservative. At paranoia level 3 or 4, even a slightly unusual User-Agent header or query parameter format can tip a request over the threshold.
APIs are particularly prone to false positives. JSON bodies with nested structures, base64-encoded values in query parameters, and unusual HTTP methods all trigger rules that were designed with HTML form submissions in mind.
Start from logs, not from rules
The single most important principle in WAF tuning is this: never start by modifying rules. Start by understanding what the WAF is currently blocking and logging — and distinguish false positives from genuine attack traffic.
In the Cloudflare dashboard, Security > Events shows you every WAF action — block, challenge, log, skip. Filter by Action: Block and review the top triggered rules over the past 7–30 days. For each rule, look at the matching requests:
- What is the source IP range and ASN? Is it consistent with known attackers (Tor exit nodes, scanning ASNs) or with legitimate API clients?
- What is the matched request URI? Is it an endpoint that legitimate users hit?
- What specific rule matched? Is the match description consistent with what you see in the request?
This process is slow but essential. Skipping it and making rule changes based on application team complaints leads to over-broad exceptions that neuter your WAF protection.
The safe tuning workflow
Once you have identified a confirmed false positive — a rule that is blocking legitimate traffic — the approach to exception creation matters significantly. The most common mistake is creating exceptions that are too broad.
Cloudflare offers several mechanisms for managing false positives, in order of preference:
Exception options, narrowest to broadest
1. Skip specific rule ID for specific path
Use a WAF Override or Skip rule scoped to the exact URI path and rule ID that is causing the false positive.
2. Skip rule for specific URI and specific source
Combine path matching with IP range or ASN conditions to further narrow the exception scope.
3. Tag-based exceptions via managed ruleset settings
Reduce the score contribution of a specific rule category for a specific path — without disabling the rule entirely.
4. Reduce paranoia level for specific paths
Lower the OWASP anomaly threshold for a specific path where the stricter rules are not appropriate.
Before deploying any exception to production, test it in Log mode (Simulate action in Cloudflare's terminology). This lets you verify that the exception applies to the traffic you intend — and not more — before it has any effect on actual WAF behavior.
Custom rules vs managed rules
Cloudflare's managed rulesets cover generic attack patterns. They do not know anything specific about your application. Custom firewall rules let you add application-specific logic — blocking requests that your managed rules do not cover, or allowing traffic patterns that your managed rules incorrectly flag.
Custom rules are expressed in Cloudflare's Ruleset Engine expression language. A rule that blocks requests to your admin path from outside your office IP range looks like:
# Block admin access from non-office IPs
(starts_with(http.request.uri.path, "/admin") and
not ip.src in {203.0.113.0/24 198.51.100.10})
# Block requests with suspicious encoded payloads
(http.request.uri.query contains "../" or
http.request.uri.query contains "%2e%2e%2f")
# Rate limit login endpoint
(http.request.uri.path eq "/api/auth/login")Rate limiting as a WAF complement
WAF rules block individual requests based on content. Rate limiting blocks sources based on request volume. The two complement each other — particularly for credential stuffing against login endpoints and scraping against data APIs.
Cloudflare rate limiting rules should be scoped as narrowly as possible. A rate limit of 10 requests per minute applied to your entire domain will block legitimate users. The same limit applied only to /api/auth/login will not — because legitimate users do not attempt to log in 10 times per minute.
Testing your WAF coverage
After tuning, verify that your WAF still catches what it should. You can test WAF rule coverage using safe, non-destructive payloads that match known attack signatures — without actually exploiting anything. Cloudflare provides a test endpoint for this purpose, and tools like GoTestWAF and OWASP's test suite can be run against a staging environment.
Warning: over-permissive exceptions
The most dangerous WAF configuration is not one with rules disabled — it is one with broad exceptions that appear enabled but do not actually protect anything. An exception like "skip all managed rules for requests to /api/*" disables WAF protection for your entire API surface. Exceptions should always be as narrow as possible: specific rule IDs, specific URI paths, and ideally combined with additional conditions like IP ranges or request methods.
WAF tuning is an ongoing process, not a one-time task. Application changes introduce new traffic patterns. New managed rules are deployed by Cloudflare. Attackers adapt their techniques. A review cadence of quarterly — combined with monitoring Security Events for new block spikes after application deployments — keeps your WAF accurate and effective over time.