You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/ruleset-engine/about/phases.mdx
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,16 +8,17 @@ sidebar:
8
8
9
9
A phase defines a stage in the life of a request where you can execute rulesets. Phases are defined by Cloudflare and cannot be modified.
10
10
11
-
Phases exist at two levels: at the **account** level and at the **zone** level. For the same phase, rules defined at the account level are evaluated **before** the rules defined at the zone level.
11
+
Phases exist at two levels:
12
12
13
-
Each phase has at most one [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) at the account and zone level.
13
+
- At the account level
14
+
- At the zone level
14
15
15
-
:::note
16
+
For the same phase, rules defined at the account level are evaluated before the rules defined at the zone level.
16
17
18
+
Each phase has at most one [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) at the account and zone level.
17
19
20
+
:::note
18
21
Currently, phases at the account level are only available in Enterprise plans.
19
-
20
-
21
22
:::
22
23
23
24
The following diagram outlines the request handling process where requests go through the available phases:
Copy file name to clipboardExpand all lines: src/content/docs/ruleset-engine/basic-operations/add-rule-phase-rulesets.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ A [phase entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-rulese
12
12
13
13
To add one or more rules to a phase entry point ruleset, use one of the [ruleset update operations](/ruleset-engine/rulesets-api/update/) of the [Rulesets API](/ruleset-engine/rulesets-api/). When you add a rule to an entry point ruleset, the entry point ruleset is created automatically if it does not exist. This API method requires that you include in the request all rules you want to keep in the ruleset, or else they will be removed.
14
14
15
-
If you are adding a **single** rule to a ruleset, consider using one of the [rule creation operations](/ruleset-engine/rulesets-api/add-rule/) instead. In this case, the request will only include the definition of the new rule.
15
+
If you are adding a single rule to a ruleset, consider using one of the [rule creation operations](/ruleset-engine/rulesets-api/add-rule/) instead. In this case, the request only includes the definition of the new rule.
16
16
17
17
:::note[Creating an entry point ruleset]
18
18
Instead of relying on the automatic creation of an entry point ruleset, you can also create this ruleset explicitly using one of the [ruleset creation operations](/ruleset-engine/rulesets-api/create/).
Copy file name to clipboardExpand all lines: src/content/docs/ruleset-engine/custom-rulesets/add-rules-ruleset.mdx
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,16 @@ sidebar:
7
7
8
8
import { APIRequest, Render } from"~/components";
9
9
10
-
To add rules to an existing custom ruleset, use the [Update an account ruleset](/api/resources/rulesets/methods/update/) operation and pass the rules in an array. Each rule has an expression and an action.
10
+
To add rules to an existing custom ruleset, use the [Update an account or zone ruleset](/api/resources/rulesets/methods/update/) operation and pass the rules in an array. Each rule has an expression and an action.
11
11
12
12
:::note[Choosing the appropriate API method]
13
13
14
-
When you add rules to a custom ruleset using the [Update an account ruleset](/api/resources/rulesets/methods/update/) operation, you replace all the rules in the ruleset with the rules in the request. Use this API method when adding or updating several rules at once. This method will update the ruleset version number only once.
14
+
When you add rules to a custom ruleset using the [Update an account or zone ruleset](/api/resources/rulesets/methods/update/) operation, you replace all the rules in the ruleset with the rules in the request. Use this API method when adding or updating several rules at once. This method will update the ruleset version number only once.
15
15
16
16
You can use other API operations depending on the type of operation:
17
17
18
-
- Add a single rule to an existing custom ruleset: Use the [Create an account ruleset rule](/api/resources/rulesets/subresources/rules/methods/create/) operation.
19
-
- Update a single rule in a custom ruleset: Use the [Update an account ruleset rule](/api/resources/rulesets/subresources/rules/methods/edit/) operation.
18
+
- Add a single rule to an existing custom ruleset: Use the [Create an account or zone ruleset rule](/api/resources/rulesets/subresources/rules/methods/create/) operation.
19
+
- Update a single rule in a custom ruleset: Use the [Update an account or zone ruleset rule](/api/resources/rulesets/subresources/rules/methods/edit/) operation.
20
20
21
21
:::
22
22
@@ -26,7 +26,7 @@ You can use other API operations depending on the type of operation:
26
26
27
27
## Add rules
28
28
29
-
The following request adds two rules to a custom ruleset with ID `$RULESET_ID`. These will be the only two rules in the ruleset.
29
+
The following request adds two rules to a custom ruleset at the account level with ID `$RULESET_ID`. These will be the only two rules in the ruleset.
30
30
31
31
The response will include the rule ID of the new rules in the `id` field.
32
32
@@ -90,9 +90,9 @@ The response will include the rule ID of the new rules in the `id` field.
90
90
91
91
## Update rules
92
92
93
-
To update one or more rules in a custom ruleset, use the [Update an account ruleset](/api/resources/rulesets/methods/update/) operation. Include the ID of the rules you want to modify in the rules array and add the fields you wish to update. The request replaces the entire ruleset with a new version. Therefore, you must include the ID of all the rules you wish to keep.
93
+
To update one or more rules in a custom ruleset, use the [Update an account or zone ruleset](/api/resources/rulesets/methods/update/) operation. Include the ID of the rules you want to modify in the rules array and add the fields you wish to update. The request replaces the entire ruleset with a new version. Therefore, you must include the ID of all the rules you wish to keep.
94
94
95
-
The following `PUT` request edits one rule in a custom ruleset and updates the execution order of the rules.
95
+
The following `PUT` request edits one rule in a custom ruleset at the account level and updates the execution order of the rules.
96
96
97
97
The response will include the modified custom ruleset. Note that the updated rule and ruleset version number increment.
The following request creates a new custom ruleset. The response will include the ID of the new custom ruleset in the `id` field.
21
+
## Example A - Custom ruleset at the account level
22
+
23
+
The following request creates a new custom ruleset at the account level. The response will include the ID of the new custom ruleset in the `id` field.
22
24
23
25
<APIRequest
24
26
path="/accounts/{account_id}/rulesets"
25
27
method="POST"
26
28
json={{
27
29
name: "Custom Ruleset 1",
28
-
description: "My First Custom Ruleset",
30
+
description: "My First Custom Ruleset (account)",
31
+
kind: "custom",
32
+
phase: "http_request_firewall_custom",
33
+
}}
34
+
/>
35
+
36
+
```json output {3}
37
+
{
38
+
"result": {
39
+
"id": "f82ccda3d21f4a02825d3fe45b5e1c10",
40
+
"name": "Custom Ruleset 1",
41
+
"description": "My First Custom Ruleset (account)",
42
+
"kind": "custom",
43
+
"version": "1",
44
+
"last_updated": "2025-08-09T10:27:30.636197Z",
45
+
"phase": "http_request_firewall_custom"
46
+
},
47
+
"success": true,
48
+
"errors": [],
49
+
"messages": []
50
+
}
51
+
```
52
+
53
+
You can include a list of rules in the custom ruleset creation request. If you have not added any rules, refer to [Add rules to a custom ruleset](/ruleset-engine/custom-rulesets/add-rules-ruleset/) for more information.
54
+
55
+
56
+
## Example B - Custom ruleset at the zone level
57
+
58
+
The following request creates a new custom ruleset at the zone level. The response will include the ID of the new custom ruleset in the `id` field.
59
+
60
+
<APIRequest
61
+
path="/zones/{zone_id}/rulesets"
62
+
method="POST"
63
+
json={{
64
+
name: "Custom Ruleset 1",
65
+
description: "My First Custom Ruleset (zone)",
29
66
kind: "custom",
30
67
phase: "http_request_firewall_custom",
31
68
}}
@@ -36,10 +73,10 @@ The following request creates a new custom ruleset. The response will include th
36
73
"result": {
37
74
"id": "f82ccda3d21f4a02825d3fe45b5e1c10",
38
75
"name": "Custom Ruleset 1",
39
-
"description": "My First Custom Ruleset",
76
+
"description": "My First Custom Ruleset (zone)",
40
77
"kind": "custom",
41
78
"version": "1",
42
-
"last_updated": "2021-03-09T10:27:30.636197Z",
79
+
"last_updated": "2025-08-09T10:27:30.636197Z",
43
80
"phase": "http_request_firewall_custom"
44
81
},
45
82
"success": true,
@@ -49,3 +86,6 @@ The following request creates a new custom ruleset. The response will include th
49
86
```
50
87
51
88
You can include a list of rules in the custom ruleset creation request. If you have not added any rules, refer to [Add rules to a custom ruleset](/ruleset-engine/custom-rulesets/add-rules-ruleset/) for more information.
Copy file name to clipboardExpand all lines: src/content/docs/ruleset-engine/custom-rulesets/deploy-custom-ruleset.mdx
+83-4Lines changed: 83 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,27 @@ description: Learn how to deploy a custom ruleset to your Cloudflare account.
8
8
9
9
import { APIRequest, Render } from"~/components";
10
10
11
-
To deploy a custom ruleset, add a rule with `execute` action to the list of rules of a phase [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) at the account level. The expression of the new rule will define when the custom ruleset will run.
11
+
To deploy a custom ruleset, add a rule with `execute` action to the list of rules of a phase [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) at the account or zone level. The expression of the new rule will define when the custom ruleset will run.
12
+
13
+
You can only deploy custom rulesets in an entry point ruleset with the same scope. For example, a custom ruleset defined at the account level can only be deployed at the account level.
1. Obtain the name of the [phase](/ruleset-engine/reference/phases-list/) where you want to deploy the custom ruleset.
20
24
2.[Create a custom ruleset](/ruleset-engine/custom-rulesets/create-custom-ruleset/) and keep the ID of the new custom ruleset.
21
25
3.[Fetch the rules already present in the phase entry point ruleset](/ruleset-engine/basic-operations/view-rulesets/#view-the-rules-included-in-a-ruleset). You must include in the `PUT` request all existing rules you want to keep.
22
26
23
-
## Example
27
+
## Example A - Account-level deployment
24
28
25
-
The following `PUT` request adds a rule that executes a custom ruleset when the zone name matches `example.com`. The response will include all the rules in the phase entry point ruleset.
29
+
The following `PUT` request adds a rule that executes a custom ruleset when the zone name matches `example.com`.
30
+
31
+
You must include in the `PUT` request the IDs of all existing rules you want to keep. The response will include all the rules in the phase entry point ruleset after the update.
@@ -110,5 +116,78 @@ The following `PUT` request adds a rule that executes a custom ruleset when the
110
116
```
111
117
112
118
:::caution
113
-
Regarding the expression of the rule deploying the ruleset, you must use parentheses to enclose any custom conditions and end your expression with `and cf.zone.plan eq "ENT"` or else the API operation will fail.
119
+
When deploying the custom ruleset at the account level, you must use parentheses to enclose any custom conditions and end your expression with `and cf.zone.plan eq "ENT"` like in the example above, or else the API operation will fail.
114
120
:::
121
+
122
+
## Example B - Zone-level deployment
123
+
124
+
The following `PUT` request adds a rule to a zone-level entry point ruleset that executes a custom ruleset for requests targeting the `/login` URI path.
125
+
126
+
You must include in the `PUT` request the IDs of all existing rules you want to keep. The response will include all the rules in the phase entry point ruleset after the update.
Copy file name to clipboardExpand all lines: src/content/docs/ruleset-engine/custom-rulesets/index.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,15 @@ sidebar:
5
5
order: 7
6
6
---
7
7
8
-
Use the following workflow to deploy a custom ruleset at the account level:
8
+
Use the following workflow to deploy a custom ruleset:
9
9
10
10
1.[Create a custom ruleset](/ruleset-engine/custom-rulesets/create-custom-ruleset/).
11
11
2.[Add rules to your custom ruleset](/ruleset-engine/custom-rulesets/add-rules-ruleset/).
12
-
3.[Add a rule to an account-level phase entry point ruleset that executes the custom ruleset](/ruleset-engine/custom-rulesets/deploy-custom-ruleset/).
12
+
3.[Add a rule to a phase entry point ruleset that executes the custom ruleset](/ruleset-engine/custom-rulesets/deploy-custom-ruleset/).
13
13
14
14
You must create a rule with `execute` action in an entry point ruleset to execute the custom ruleset (step 3 in the previous procedure). If you skip this step, the rules of the custom ruleset will not run.
15
15
16
-
Currently, custom rulesets are only supported by the [Cloudflare WAF](/waf/).
16
+
Currently, custom rulesets are only supported by the [Cloudflare WAF](/waf/), both at the account and the zone level.
17
17
18
18
:::note
19
19
You cannot execute a custom ruleset from another custom ruleset, only from an entry point ruleset.
You can only use the _Get a zone ruleset_ operation for zone-level phase entry points (entry points where `kind` is set to `zone`).
77
+
You can only use the [Get a zone ruleset](/api/resources/rulesets/methods/get/) operation for zone-level phase entry points (entry points where `kind` is set to `zone`).
78
78
:::
79
79
80
80
The API returns a `404 Not Found` HTTP status code under these conditions:
0 commit comments