Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Firewall Rules, Filters API, Expression Language, and WAF Migration

How legacy HTTP firewall rules combine filters and actions, how to manage them in the dashboard and API, and how to move to WAF custom rules.

This page summarises Cloudflare documentation on Cloudflare Firewall Rules: matching incoming HTTP traffic with Rules language expressions, applying actions, and managing rules in the dashboard or through the Firewall Rules API and Cloudflare Filters API. That product is deprecated; existing rules were moved to WAF custom rules, and new work should use the Rulesets API or dashboard custom rules. The legacy APIs remain documented because many teams still maintain automation or need to understand filter–rule separation during migration.

Firewall rules: what matches traffic and what happens next

Section titled “Firewall rules: what matches traffic and what happens next”

Cloudflare Firewall Rules lets you create rules that inspect incoming traffic and block, challenge, log, or allow specific requests.

Cloudflare Firewall Rules is a flexible and intuitive framework for filtering HTTP requests. It gives you fine-grained control over which requests reach your applications, proactively inspecting incoming site traffic and automatically responding to threats.

— Cloudflare, About Firewall Rules

In practice, people ask “how do I block or challenge only certain requests?” A firewall rule has two main attributes: an expression (when the rule applies) and an action (what Cloudflare does). When an incoming HTTP request matches the expression, Cloudflare performs the specified action. For field lists and action values, see Expressions and Actions in Cloudflare’s firewall rules docs.

The maximum length of a rule expression is 4,096 characters. Very long conditions can block migration to WAF custom rules if they exceed 4 KB—Cloudflare lists that as a case where you may need support for upgrade errors.

Filters API: reusable match criteria separate from actions

Section titled “Filters API: reusable match criteria separate from actions”

A filter answers “if traffic matches certain criteria, then…” without by itself defining the action. It holds a Rules language expression that evaluates to true or false for each request.

A filter is a way of saying:

if (traffic matches certain criteria) then…

A filter contains an expression that would return true or false when evaluated against traffic passing through Cloudflare.

— Cloudflare, What is a filter?

Cloudflare Filters is an API-only component for designing complex criteria with boolean operators. You associate a filter with a firewall rule to define the scope of that rule. Expressions can reference IP lists (named groups of addresses); see the Lists API via Manage rules via the APIs.

Piece Role Typical JSON fields
Filter Match logic only expression, paused, description (max 500 chars), ref (max 50)
Firewall rule Match + action filter, action, priority, paused, description

Filter and rule objects are documented in Filter JSON object and Firewall rule JSON object. To write expressions, use the Rules language (Wireshark Display Filter–inspired syntax described in About Firewall Rules).

Dashboard: create, order, and pause firewall rules

Section titled “Dashboard: create, order, and pause firewall rules”

To configure firewall rules in the dashboard, open Firewall rules under Security > WAF (Manage rules in the dashboard). After upgrade, the same rules appear as custom rules—old UI: Security > WAF > Custom rules; new security dashboard: Security > Security rules (Firewall rules upgrade).

  1. Log in to the Cloudflare dashboard, select your account and website, and go to Security > WAF > Firewall rules (Create, edit, and delete rules).
  2. Select Create a firewall rule, set a Rule name, and under When incoming requests match choose fields or use the Expression Editor.
  3. Select an Action, then Deploy (live) or Save as draft.
  4. Use the list toggle to enable or disable a rule; use Edit (wrench icon) to change it (Create, edit, and delete rules).

By default, Cloudflare evaluates firewall rules in list order (top to bottom; drag-and-drop reordering). Once there are more than 200 total rules (including inactive), you must use priority ordering: evaluation by priority number, lowest first (Order and priority, Create, edit, and delete rules).

Priority ordering when you have many rules

Section titled “Priority ordering when you have many rules”

When priority ordering is enabled, tie-breaking uses action precedence if two rules share the same priority (with nuances for Log and Bypass—see firewall rules actions in Cloudflare docs). Rules without a priority number are evaluated last, ordered by action precedence. Cloudflare suggests avoiding priority 1 and grouping numeric ranges (e.g. 5000–9999 for trusted IPs) (Order and priority).

Firewall Rules API and Filters API: endpoints and call patterns

Section titled “Firewall Rules API and Filters API: endpoints and call patterns”

Cloudflare offers APIs that work together like the UI: Firewall Rules API (rules and actions), Filters API (match criteria), and Lists API (named lists for expressions) (Manage rules via the APIs).

Base URL for zone-scoped calls:

https://api.cloudflare.com/client/v4/

Both APIs require <ZONE_ID>; list zones first per Filters endpoints and Firewall Rules endpoints.

API Create List Update Delete
Filters POST zones/<ZONE_ID>/filters GET zones/<ZONE_ID>/filters (25/page) PUT (batch or single) DELETE with id= query params
Firewall rules POST zones/<ZONE_ID>/firewall/rules GET zones/<ZONE_ID>/firewall/rules PUT (batch up to 25) DELETE with rule IDs

Batch POST/PUT operations are single transactions: one failure fails the whole batch (Filters endpoints, Firewall Rules endpoints).

Unlike most Cloudflare APIs, these accept arrays of items in one call, and errors follow the JSON API standard so you can see which array element failed (Cloudflare Filters API, Firewall Rules API).

Recommended two-step create vs single POST with embedded filter

Section titled “Recommended two-step create vs single POST with embedded filter”

Cloudflare strongly recommends creating a filter first, then creating firewall rules that reference filter.id—this improves filter reusability across rules and other features (Call sequence).

For emergencies, a single POST to /firewall/rules can embed a filter object to create both in one call (Call sequence). Downsides include combined error handling, and PUT/DELETE on filters created this way are not allowed when protecting shared filters. By default, if either part is invalid, neither is created—except near rule quota, when a filter may be created without a rule (Call sequence).

Creating rules after filters requires an existing filter id (POST example — firewall rules). PUT on a firewall rule updates the rule only; it uses filter.id to point at a filter but does not update filter fields—use the Filters API for expression changes (PUT examples — firewall rules). DELETE on a firewall rule does not delete its filter (DELETE examples — firewall rules).

Use GET or POST on filters/validate-expr to catch syntax errors (invalid IPs, invalid CIDR masks, etc.) before creating filters (Expression validation).

WAF custom rules migration: Rulesets API and Terraform

Section titled “WAF custom rules migration: Rulesets API and Terraform”

Cloudflare upgraded existing firewall rules into custom rules with the same protection level plus extra features (e.g. custom responses for blocked requests, Skip action) not available on the deprecated Firewall Rules API (Firewall rules upgrade).

The preferred API for managing WAF custom rules is the Rulesets API. The Rulesets API is used on all recent Cloudflare security products to provide a uniform user experience when interacting with our API.

— Cloudflare, Firewall rules upgrade

API users: migrate automation from Firewall Rules API and Filters API to the Rulesets API before issues arise. Rule IDs differ between legacy firewall rules and custom rules. Until full sunset, Cloudflare may internally convert legacy API calls to Rulesets API calls; audit logs may show those as generated by Cloudflare, not your user (Firewall rules upgrade).

Terraform: replace cloudflare_firewall_rule and cloudflare_filter with cloudflare_ruleset using phase http_request_firewall_custom (Firewall rules upgrade, API deprecations).

Deprecated HTTP endpoints are listed under 2025-06-15 in API deprecations (all zones/:zone_id/firewall/rules and zones/:zone_id/filters routes). Replacement: WAF custom rules.

URL normalization and path-based expressions

Section titled “URL normalization and path-based expressions”

Enabling Normalize incoming URLs feeds canonical paths into matchers. Cloudflare did not auto-enable normalization on zones whose rules used http.request.uri.path, http.request.full_uri, or http.request.uri in ways that would change behavior (Required firewall rule changes to enable URL normalization). Review path-based rules before toggling normalization.

Common mistakes when using firewall rules and the legacy APIs

Section titled “Common mistakes when using firewall rules and the legacy APIs”
  1. In the Cloudflare dashboard, open Security > WAF (or Security > Security rules on the new dashboard) and confirm whether rules appear as custom rules after Firewall rules upgrade.
  2. List current rules with GET https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules or filters with GET .../filters only if you still maintain legacy automation; otherwise verify via the Rulesets API per Firewall rules upgrade.
  3. Validate a suspect expression with Expression validation before changing production filters.
  4. If migration fails (e.g. more than 200 rules to migrate or expressions over 4 KB), follow Possible upgrade errors and contact Cloudflare Support if needed.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.