Cloudflare Docs
Waf
Visit WAF on GitHub
Set theme to dark (⇧+D)

API examples of custom rules with the Skip action

Use the Rulesets API to configure custom rules via API.

The skip action supports different skip options , according to the security features or products that you wish to skip.

The following sections provide examples for the different skip rule scenarios available for custom rules.

Take the following into account regarding the provided examples:

  • The <ZONE_ID> value is the ID of the zone where you want to add the rule. To retrieve a list of zones you have access to, use the List Zones operation.

  • The <RULESET_ID> value is the ID of the entry point ruleset of the http_request_firewall_custom phase. For details on obtaining this ruleset ID, refer to List and view rulesets . If you do not have such a ruleset yet, you can use the Update zone entry point ruleset API operation to create the entry point ruleset with a skip rule in a single operation.

  • The examples in this page add a new rule at the zone level with the skip action. If you wish to edit an existing rule, refer to Update a rule in a ruleset for more information.

  • Although each example only includes one action parameter, you can use several skip options in the same rule by specifying the ruleset, phases, and products action parameters simultaneously.

Skip the remaining rules in the current ruleset

This example uses the Add individual rule API operation to add a rule that skips the remaining rules in the current ruleset:

---
header: Request
highlight: [6,7,8,9]
---
curl -X POST \
"https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/rulesets/<RULESET_ID>/rules" \
-H "Authorization: Bearer <API_TOKEN>" \
-d '{
  "action": "skip",
  "action_parameters": {
    "ruleset": "current"
  },
  "expression": "http.request.uri.path contains \"/skip-current-ruleset/\"",
  "description": ""
}'

Skip a phase

This example uses the Add individual rule API operation to add a rule that skips the http_ratelimit phase:

---
header: Request
highlight: [6,7,8,9,10,11]
---
curl -X POST \
"https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/rulesets/<RULESET_ID>/rules" \
-H "Authorization: Bearer <API_TOKEN>" \
-d '{
  "action": "skip",
  "action_parameters": {
    "phases": [
      "http_ratelimit"
    ]
  },
  "expression": "http.request.uri.path contains \"/skip-phase/\"",
  "description": ""
}'

Refer to Available skip options for the list of phases you can skip.

Skip security products

This example uses the Add individual rule API operation to add a rule that skips the Zone Lockdown and User Agent Blocking products:

---
header: Request
highlight: [6,7,8,9,10,11,12]
---
curl -X POST \
"https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/rulesets/<RULESET_ID>/rules" \
-H "Authorization: Bearer <API_TOKEN>" \
-d '{
  "action": "skip",
  "action_parameters": {
    "products": [
      "zoneLockdown",
      "uaBlock"
    ]
  },
  "expression": "http.request.uri.path contains \"/skip-products/\"",
  "description": ""
}'

Refer to Available skip options for the list of products you can skip.