Skip to content
AnswerWell geo Documentation

Research · 11 min read · Answerwell

WAF Ruleset Phases, Entry Point Deployment, and Rulesets API

How rulesets, phases, and entry points work in Cloudflare WAF: deploy with execute rules, API CRUD, overrides, account-level config, Terraform, and legacy migration.

This page summarises Cloudflare documentation on the Ruleset Engine as used for Web Application Firewall (WAF) and related HTTP phases: what a ruleset is, how you deploy it through phase entry points, which API calls to use, and how account-level Enterprise WAF, managed ruleset overrides, Terraform, and legacy WAF migration fit together.

A ruleset is an ordered set of rules applied on Cloudflare’s network. Each ruleset belongs to exactly one phase and only runs in that phase.

A ruleset is an ordered set of rules that you can apply to traffic on the Cloudflare global network. Rulesets belong to a phase and can only execute in the same phase.

— Cloudflare, Rulesets

Kinds you work with most often:

Kind Typical scope Role
root Account Account-level entry point ruleset for a phase
zone Zone Zone-level entry point ruleset for a phase
custom Account or zone Your own ruleset; must be referenced from an entry point
managed Cloudflare-owned Prebuilt rulesets (WAF, OWASP, DDoS, and others) you deploy via execute

A phase entry point ruleset is the ordered rule list Cloudflare evaluates first in that phase at account or zone scope. There is at most one entry point per phase per scope. Rules in the entry point can use action execute to run another ruleset by ID.

A phase entry point ruleset contains an ordered list of rules that run in that phase. A rule in an entry point ruleset can execute a different ruleset.

— Cloudflare, Add rules to phase entry point rulesets

Each change creates a new version; deployment normally uses the latest unless you pin version. Custom rulesets for WAF use phase http_request_firewall_custom at zone level for all plans; account-level custom rulesets require Enterprise. See Custom rulesets and Custom rulesets (zone level).

Deploy rulesets: execute, expressions, and phases

Section titled “Deploy rulesets: execute, expressions, and phases”

How to wire a ruleset so traffic actually hits it

Section titled “How to wire a ruleset so traffic actually hits it”

Creating a custom ruleset does not turn it on. You must add a rule to the phase entry point with action: execute and action_parameters.id set to the ruleset ID, plus an expression for when that ruleset runs (zone-wide deploy often uses expression: true).

Use the Rulesets API to deploy a ruleset. To deploy a ruleset, add a rule with “action”: “execute” to a phase entry point ruleset, specifying the ruleset ID to execute as an action parameter.

— Cloudflare, Deploy rulesets

Creating a custom ruleset does not activate it. Custom rulesets only run when a rule with the execute action references them from a phase entry point ruleset

— Cloudflare, Custom rulesets (zone level)

Deploy the custom ruleset by adding an execute rule to a phase entry point ruleset. If you skip this step, the rules of the custom ruleset will not run.

— Cloudflare, Work with custom rulesets

Account-level custom rulesets must be deployed from an account entry point with the same scope (account custom ruleset → account entry point). You cannot chain custom rulesets: only an entry point may execute a custom ruleset, not another custom ruleset.

Phase Typical use
http_request_firewall_managed WAF managed rulesets on the request
http_response_firewall_managed Sensitive Data Detection on the response
http_request_firewall_custom Custom WAF rules and custom rulesets
http_ratelimit Rate limiting rulesets
ddos_l7 HTTP DDoS managed ruleset overrides

WAF managed rulesets deploy in http_request_firewall_managed; see Deploy a managed ruleset to a zone via API. Other products (redirects, origin rules, transforms, Logpush custom fields) use other phases listed in the Rulesets API endpoints table.

Shortcut for entry point updates: instead of PUT by ruleset ID, you can use PUT /zones/{zone_id}/rulesets/phases/{phase_name}/entrypoint (and the account equivalent). Base URL: https://api.cloudflare.com/client/v4 per Endpoints.

Use View rulesets to list or get the phase entry point. If the entry point does not exist yet, adding a rule may auto-create it; update operations must include every rule you intend to keep. A managed ruleset GET returns 404 if the zone is not entitled.

Rulesets API: POST vs PUT vs PATCH and rule order

Section titled “Rulesets API: POST vs PUT vs PATCH and rule order”
Operation Method When to use Risk
Create ruleset POST .../rulesets New ruleset (kind, phase, optional rules); name is immutable See Magic Firewall caveat below
Replace all rules PUT .../rulesets/{id} or phase entry point PUT Full desired rules array Omitted rules are deleted
Add one rule POST .../rulesets/{id}/rules Append without resending entire list Creates new version
Change one rule PATCH .../rules/{rule_id} Edit or reorder single rule Creates new version
Remove rule DELETE .../rules/{rule_id} Drop one rule Returns full ruleset
Delete ruleset DELETE .../rulesets/{id} Remove unused ruleset Fails if still referenced by execute

The Update an account or zone ruleset operation replaces all the rules in the ruleset with the rules in the request.

— Cloudflare, Add rules to a custom ruleset

If you omit an existing rule from the rules array, it will not appear in the new version of the ruleset.

— Cloudflare, Add rules to a custom ruleset

Adds a single rule to an existing ruleset. Use this endpoint to add a rule without having to include all the existing ruleset rules in the request.

— Cloudflare, Add a rule to a ruleset

You cannot delete a ruleset that is still referenced in other rules. For example, you cannot delete a custom ruleset that is being deployed in a rule with execute action.

— Cloudflare, Delete a ruleset

Rule order: on POST or PATCH, set position to one of before, after, or index (1-based). Only one position field at a time; invalid index returns 400. Details: Add a rule, Update a rule.

Use ref on rules for stable Terraform references; see JSON object definitions.

WAF: custom rules, custom rulesets, and managed rulesets

Section titled “WAF: custom rules, custom rulesets, and managed rulesets”

A zone custom rule is a rule added directly to the http_request_firewall_custom entry point, not a separate ruleset container. See Create a custom rule via API.

A custom ruleset workflow: (1) POST with kind: custom and phase: http_request_firewall_custom; (2) add rules; (3) execute from the entry point with your match expression. Account API steps: Create a custom ruleset using the API. Dashboard (account): Create a custom ruleset in the dashboard — account custom rulesets require Enterprise; scope can be all Enterprise traffic or a custom filter.

Managed rulesets: zone once, account many times

Section titled “Managed rulesets: zone once, account many times”

At zone level, each managed ruleset is deployed once per zone. At account level, the same managed ruleset can be deployed multiple times with different expressions and overrides. Overview: Managed rules, Managed rulesets (account).

Avoid deploying the same managed ruleset at both the account level and the zone level. Account-level rulesets run before zone-level rulesets, so duplicated deployments evaluate the same request twice, and a zone-level exception will not prevent a match at the account level.

— Cloudflare, Managed rulesets (account)

Common managed ruleset IDs from documentation examples:

Ruleset ID
Cloudflare Managed Ruleset efb7b8c949ac4650a09736fc376e9aee
Cloudflare OWASP Core Ruleset 4814384a9e5d4991b9815dcfc25d2f1f
Cloudflare Sensitive Data Detection e22d83c647c64a3eae91b71b499d988e

Deploy managed rulesets at zone: Deploy via API. At account: Deploy WAF managed ruleset via API and Deploy a managed ruleset.

Managed ruleset overrides on the execute rule

Section titled “Managed ruleset overrides on the execute rule”

Overrides live under action_parameters.overrides on the execute rule in the entry point. Three levels: Override a managed ruleset.

  1. Ruleset override — e.g. disable all rules or set action: log for all enabled rules.
  2. Tag/category override — categories with category, enabled, action; tag overrides beat ruleset-level settings; later list entries beat earlier ones. Example: Enable only Joomla rules.
  3. Rule override — rules with id, enabled, action, score_threshold, sensitivity_level, and related fields.

Tag overrides take precedence over ruleset overrides. Only the rules with the specified tag are enabled, and all other rules are disabled.

— Cloudflare, Enable only Joomla rules

For Terraform-managed WAF:

Ruleset overrides and tag overrides apply to both existing and future rules in the managed ruleset. If you want to override existing rules only, you must use rule overrides.

— Cloudflare, WAF Managed Rules configuration using Terraform

OWASP paranoia levels can be tuned via category overrides; see Configure OWASP via API. Payload logging uses action_parameters.matched_data.public_key on the execute rule; see Configure payload logging via API. L7 DDoS overrides use phase ddos_l7; see HTTP DDoS overrides via API and DDoS managed rulesets in Terraform.

Account-level WAF: one config for Enterprise zones

Section titled “Account-level WAF: one config for Enterprise zones”

The account-level Web Application Firewall (WAF) configuration allows you to define a configuration once and apply it to multiple Enterprise zones in your account. Instead of configuring each zone individually, you create rulesets at the account level and use expressions to control which zones and traffic they apply to.

— Cloudflare, Account-level WAF configuration

Account-level WAF needs Enterprise and (for managed rules at account) a paid add-on per WAF Managed Rules configuration using Terraform. Traffic from non-Enterprise zones is out of scope for account deploy expressions.

API expression requirements (requests fail or behave wrongly if you skip them):

In the dashboard Expression Editor for account rate limiting, include AND zone.level eq "ENT" when needed. Create rate limiting ruleset in the dashboard.

For account custom rulesets in the dashboard, wrap custom conditions in parentheses and end with and cf.zone.plan eq "ENT". Create a custom ruleset in the dashboard.

Multi-zone patterns (defaults, hostname exceptions, logging) are described in Streamlined WAF deployment across zones and applications.

Terraform, legacy WAF migration, and API tokens

Section titled “Terraform, legacy WAF migration, and API tokens”

Zone example: cloudflare_ruleset with phase = "http_request_firewall_managed", kind = "zone", and execute rules pointing at managed ruleset IDs. Account example: kind = "root", account_id, execute expression ending with and cf.zone.plan eq "ENT". Full examples: WAF Managed Rules configuration using Terraform.

Zone token: at least Zone WAF Write.

Account token: Account WAF Write and Account Rulesets Write (all required).

Custom WAF and rate limiting Terraform: WAF custom rules, Rate limiting rules.

  1. Check compatibility: GET .../zones/{zone_id}/waf_migration/check?phase_two=1 — "compatible": true means you can proceed. Upgrade from old WAF managed rules.
  2. Preview new config: GET .../waf_migration/config?phase_two=1.
  3. Validation mode (Enterprise only): PUT .../rulesets/phases/http_request_firewall_managed/entrypoint?waf_migration=validation&phase_two=1 runs old and new WAF together; review Security Events for false blocks.
  4. Finish: PUT with waf_migration=pending&phase_two=1 saves the new config and disables the old WAF automatically.

This will make sure that your zone stays protected by one of the WAF versions during the update process.

— Cloudflare, Upgrade from old WAF managed rules

Pro and Business zones without validation: you may edit the zone entry point without waf_migration=pending&phase_two=1, but every rule in the configuration must be "enabled": false unless you are Enterprise configuring enabled managed-ruleset deploy rules (which triggers upgrade rules). Only Enterprise can run enabled deploy rules without those migration query params.

Terraform migration: generate rulesets with cf-terraforming generate --zone <ZONE_ID> --resource-type "cloudflare_ruleset", import http_request_firewall_managed, then remove legacy cloudflare_waf_package, cloudflare_waf_group, and cloudflare_waf_rule from state before deleting .tf files. See Firewall rules upgrade and the upgrade doc above.

Task Permissions
Zone WAF managed rules (API/Terraform) Zone WAF Write (minimum)
Account WAF managed/custom deploy Account WAF Write + Account Rulesets Write
Configuration rules Zone > Config Rules > Edit minimum
HTTP DDoS ruleset (Terraform) HTTP DDoS Managed Ruleset Write

Create rulesets and rules per operation tables in Create ruleset and linked WAF pages.

  1. PUT without the full rules array — drops rules silently; use POST/PATCH for small edits.
  2. POST /accounts/.../rulesets to “add a policy” when a deployment already exists — can replace all policies (Magic Firewall / packet filtering).
  3. Missing cf.zone.plan eq "ENT" on account-level execute rules for custom, rate limit, or managed WAF.
  4. Custom ruleset created but no entry point execute rule — rules never run.
  5. Delete ruleset still referenced by execute — delete fails until you remove the execute rule.
  6. Same managed ruleset at account and zone — double evaluation; zone exceptions do not undo account matches.
  7. Wrong phase — e.g. Sensitive Data Detection uses http_response_firewall_managed, not the request firewall phase.
  8. Tag/ruleset overrides when you only meant to change today’s rules — use per-rule overrides if future managed rules must stay default.
  9. Terraform: delete legacy cloudflare_waf_* from .tf before terraform state rm the old resources.
  1. In the Cloudflare dashboard, open WAF → Custom rulesets or managed rules views and confirm entry point rules show execute actions with the expected ruleset IDs, matching Create a custom ruleset in the dashboard or your zone WAF settings.

  2. Call GET https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint (or the account phase URL from Endpoints) and verify execute rules, expressions, and action_parameters.id / overrides match intent. Use View rulesets to list rulesets.

  3. If migrating from legacy WAF, run GET .../waf_migration/check?phase_two=1 and, when eligible, compare output of GET .../waf_migration/config?phase_two=1 with your entry point before enabling validation or pending migration. See Upgrade from old WAF managed rules.

  4. After changes, trigger test requests and review WAF activity in Security Events (especially after Enterprise validation mode with both WAF versions enabled).

  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.