Understand the expression language: Cloudflare WAF custom rules use Wireshark-style filter expressions evaluated against HTTP request fields; key fields include http.request.uri.path, http.request.method, ip.src, http.user_agent, cf.bot_management.score, and http.request.headers.
Combine fields with operators (eq, contains, matches for regex, in for sets) and logical connectives (and, or, not); parentheses control evaluation order—for example: (http.request.uri.path contains "/admin" and not ip.src in {YOUR_CIDR_LIST}).
Deploy rules to a zone via the Rulesets API: POST to /zones/{zone_id}/rulesets/{ruleset_id}/rules with a JSON body containing the expression string in the expression field and the action (block, challenge, skip, log, js_challenge, or managed_challenge) in the action field.
Use the log action first when introducing a new rule to observe matching traffic without blocking; review Firewall Events in the dashboard or Security Analytics to confirm the rule targets only intended traffic before switching to block.
Add a description field to every rule and use a consistent naming convention; rules within a phase execute in order—set the position field in the API payload (before, after, or index) to control evaluation sequence relative to managed rulesets.
Test expressions in the Cloudflare dashboard Expression Builder before deploying via API; the UI validates syntax and shows a preview of matched sample traffic.
Known gotchas
The http.request.headers field requires the Header Modification feature on appropriate plan tiers; some header-based fields are plan-gated—verify field availability for your plan before building expressions that depend on them.
Regex matching via the matches operator uses RE2 syntax, not PCRE; back-references and lookaheads are not supported, and overly complex patterns can be rejected by the API with a validation error.
Custom rules at the zone level are separate from Account-level WAF rules; zone rules apply only to that zone's traffic, while account-level rules require scoping with zone expressions to target specific hostnames.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp