Add an exception via API
To add a managed rules exception using the API, create a rule with skip
action in a phase entry point ruleset of the http_request_firewall_managed
phase. You can define exceptions at the account level and at the zone level. Exceptions are also called skip rules.
To configure the exception, define the action_parameters
object according to the exception type. Refer to the following examples:
- Skip all remaining rules
- Skip the Cloudflare Managed Ruleset
- Skip one or more rules of WAF managed rulesets
For more information on creating exceptions using the API, refer to Create an exception in the Ruleset Engine documentation.
The following example adds a rule that skips all remaining rules in the entry point ruleset for requests matching the dev.example.com
hostname.
-
Invoke the Get a zone entry point ruleset operation to obtain the current configuration of the entry point ruleset of the
http_request_firewall_managed
phase.Save the entry point ruleset ID (
060013b1eeb14c93b0dcd896537e0d2c
) for the next step. -
Invoke the Create a zone ruleset rule operation (a
POST
request) to add an exception (or skip rule) at the beginning of the rules list, since a skip rule applies only to rules listed after it. The exact rule location is defined in theposition
object.
For more information on skipping all remaining rules via API, refer to Create an exception in the Ruleset Engine documentation.
The following example adds a rule that skips the Cloudflare Managed Ruleset for requests matching the dev.example.com
hostname.
-
Invoke the Get a zone entry point ruleset operation to obtain the current configuration of the entry point ruleset of the
http_request_firewall_managed
phase.Identify the rule deploying the Cloudflare Managed Ruleset by searching for an
execute
rule withaction_parameters
>id
equal to...376e9aee
(the managed ruleset ID).Save the following IDs for the next step:
- The ID of the entry point ruleset (
060013b1eeb14c93b0dcd896537e0d2c
in this example) - The ID of the
execute
rule deployment the managed ruleset (1bdb49371c1f46958fc8b985efcb79e7
in this example)
- The ID of the entry point ruleset (
-
Invoke the Create a zone ruleset rule operation (a
POST
request) to add an exception (or skip rule) immediately before theexecute
rule deploying the Cloudflare Managed Ruleset, since a skip rule applies only to rules listed after it. The exact rule location is defined in theposition
object.
For more information on skipping one or more managed rulesets via API, refer to Create an exception in the Ruleset Engine documentation.
The following example adds a rule that skips a particular rule of the Cloudflare Managed Ruleset for requests matching the dev.example.com
hostname.
-
Invoke the Get a zone ruleset operation to obtain a list of rules in the Cloudflare Managed Ruleset (ruleset ID
...376e9aee
).
You can get the managed ruleset details using the account-level endpoint (Get an account ruleset) or the zone-level endpoint (Get a zone ruleset).Take note of the ID of the rule you want to skip (
...0e48a85d
in this example). -
Invoke the Get a zone entry point ruleset operation to obtain the current configuration of the entry point ruleset of the
http_request_firewall_managed
phase.Identify the rule deploying the Cloudflare Managed Ruleset by searching for an
execute
rule withaction_parameters
>id
equal to...376e9aee
(the managed ruleset ID).Save the following IDs for the next step:
- The ID of the entry point ruleset (
060013b1eeb14c93b0dcd896537e0d2c
in this example) - The ID of the
execute
rule deploying the Cloudflare Managed Ruleset (1bdb49371c1f46958fc8b985efcb79e7
in this example)
You will also use the following IDs:
- The ID of the Cloudflare Managed Ruleset (
...376e9aee
) - The ID of the rule to skip (
...0e48a85d
in this example)
- The ID of the entry point ruleset (
-
Invoke the Create a zone ruleset rule operation (a
POST
request) to add an exception (or skip rule) immediately before theexecute
rule deploying the Cloudflare Managed Ruleset, since a skip rule applies only to rules listed after it.
The action_parameters
> rules
object contains the ID of the Cloudflare Managed Ruleset with an associated list of rule IDs to skip (in this case, only one rule). The position
object defines the exact rule placement in the entry point ruleset (before rule 1bdb49371c1f46958fc8b985efcb79e7
).
For more information on skipping one or more rules of managed rulesets via API, refer to Create an exception in the Ruleset Engine documentation.