Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions src/content/docs/firewall/api/cf-filters/endpoints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ sidebar:
head:
- tag: title
content: Endpoints - Filters

---



To invoke a Cloudflare Filters API operation, append the endpoint to the Cloudflare API base URL:

```txt
Expand All @@ -23,19 +20,16 @@ For help with endpoints and pagination, refer to [Getting Started: Endpoints](/f

:::note


The Filters API endpoints require a value for `<ZONE_ID>`.

To retrieve a list of zones associated with your account, use the [List Zones](/api/resources/zones/methods/list/) operation and note the Zone ID associated with the domain for which you want to manage filters.


:::

The Cloudflare Filters API supports the operations outlined below. Visit the pages in this section for examples.



<table style="table-layout:fixed; width:100%">
{/* prettier-ignore */}
<table>
<thead>
<tr>
<th style="width: 20%">Operation</th>
Expand All @@ -49,7 +43,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/create/">Create filters</a>
</td>
<td>
<code class="InlineCode">POST zones/&lt;ZONE_ID&gt;/filters</code>
<code>POST zones/&lt;ZONE_ID&gt;/filters</code>
</td>
<td>Handled as a single transaction. If there is an error, the entire operation fails.</td>
</tr>
Expand All @@ -58,7 +52,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/list/">Get filters</a>
</td>
<td>
<code class="InlineCode">GET zones/&lt;ZONE_ID&gt;/filters</code>
<code>GET zones/&lt;ZONE_ID&gt;/filters</code>
</td>
<td>
Lists all current filters. Results return paginated with 25 items per page by default. Use
Expand All @@ -70,9 +64,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/get/">Get a filter</a>
</td>
<td>
<code class="InlineCode">
GET zones/&lt;ZONE_ID&gt;/filters/&lt;FILTER_ID&gt;
</code>
<code>GET zones/&lt;ZONE_ID&gt;/filters/&lt;FILTER_ID&gt;</code>
</td>
<td>Retrieve a single filter by ID.</td>
</tr>
Expand All @@ -81,7 +73,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/bulk_update/">Update filters</a>
</td>
<td>
<code class="InlineCode">PUT zones/&lt;ZONE_ID&gt;/filters</code>
<code>PUT zones/&lt;ZONE_ID&gt;/filters</code>
</td>
<td>
Handled as a single transaction. All filters must exist for operation to succeed. If there
Expand All @@ -93,9 +85,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/update/">Update a filter</a>
</td>
<td>
<code class="InlineCode">
PUT zones/&lt;ZONE_ID&gt;/filters/&lt;FILTER_ID&gt;
</code>
<code>PUT zones/&lt;ZONE_ID&gt;/filters/&lt;FILTER_ID&gt;</code>
</td>
<td>Update a single filter by ID.</td>
</tr>
Expand All @@ -104,7 +94,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/bulk_delete/">Delete filters</a>
</td>
<td>
<code class="InlineCode">DELETE zones/&lt;ZONE_ID&gt;/filters</code>
<code>DELETE zones/&lt;ZONE_ID&gt;/filters</code>
</td>
<td>
<p>Delete existing filters. Must specify list of filter IDs.</p>
Expand All @@ -119,9 +109,7 @@ The Cloudflare Filters API supports the operations outlined below. Visit the pag
<a href="/api/resources/filters/methods/delete/">Delete a filter</a>
</td>
<td>
<code class="InlineCode">
DELETE zones/&lt;ZONE_ID&gt;/filters/&lt;FILTER_ID&gt;
</code>
<code>DELETE zones/&lt;ZONE_ID&gt;/filters/&lt;FILTER_ID&gt;</code>
</td>
<td>Delete a filter by ID.</td>
</tr>
Expand Down
68 changes: 62 additions & 6 deletions src/content/docs/firewall/api/cf-filters/json-object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,78 @@ sidebar:
head:
- tag: title
content: Filter JSON object

---

import { Type } from "~/components";

## Filter object structure and properties

A JSON response for the [Filters API](/api/resources/filters/methods/list/) has this structure:

```json
{
"id": "6f58318e7fa2477a23112e8118c66f61",
"expression": "http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\"",
"paused": true,
"description": "WordPress login paths",
"ref": ""
"id": "6f58318e7fa2477a23112e8118c66f61",
"expression": "http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\"",
"paused": true,
"description": "WordPress login paths",
"ref": ""
}
```

The following table summarizes the object properties:

{/* prettier-ignore */}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<table>
<thead>
<tr>
<th>Property</th>
<th>Description</th>
<th>Constraints</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>id</code><br />
<Type text="String" />
</td>
<td>A UUIDv4 identifier generated by Cloudflare.</td>
<td>
<p>Unique, read only</p>
<p>Length: 32 characters</p>
</td>
</tr>
<tr>
<td>
<code>expression</code><br />
<Type text="String" />
</td>
<td>A Rules language expression used to evaluate requests. For more information, refer to <a href="/ruleset-engine/rules-language/expressions/">Expressions</a>.</td>
<td></td>
</tr>
<tr>
<td>
<code>paused</code><br />
<Type text="Boolean" />
</td>
<td>Returns <code>true</code> when the filter is not active. Use <code>ref</code> to enable/disable the filter.</td>
<td>Default: <code>false</code></td>
</tr>
<tr>
<td>
<code>description</code><br />
<Type text="String" />
</td>
<td>An informative summary of the filter.</td>
<td>Maximum length: 500 characters</td>
</tr>
<tr>
<td>
<code>ref</code><br />
<Type text="String" />
</td>
<td>A short string for tagging filters.</td>
<td>Maximum length: 50 characters</td>
</tr>
</tbody>
</table>
122 changes: 104 additions & 18 deletions src/content/docs/firewall/api/cf-firewall-rules/json-object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,130 @@ sidebar:
head:
- tag: title
content: Firewall rules JSON object

---

import { Type } from "~/components";

## Firewall rule example JSON response

A JSON response for the [Firewall Rules API](/api/resources/firewall/subresources/rules/methods/list/) has this structure:

```json
{
"id": "772bf1026a72c400ea576db1ffa16407",
"filter": {
"id": "6f58318e7fa2477a23112e8118c66f61",
"expression": "http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\"",
"paused": false,
"description": "WordPress login paths",
"ref": ""
},
"action": "challenge",
"priority": 1000,
"paused": false,
"description": "Protect blog login page",
"ref": ""
"id": "772bf1026a72c400ea576db1ffa16407",
"filter": {
"id": "6f58318e7fa2477a23112e8118c66f61",
"expression": "http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\"",
"paused": false,
"description": "WordPress login paths",
"ref": ""
},
"action": "challenge",
"priority": 1000,
"paused": false,
"description": "Protect blog login page",
"ref": ""
}
```

This table summarizes the object properties:


{/* prettier-ignore */}
<table>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Constraints</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>id</code><br />
<Type text="String" />
</td>
<td>A UUIDv4 identifier generated by Cloudflare.</td>
<td>
<p>Unique, read only</p>
<p>Length: 32 characters</p>
</td>
</tr>
<tr>
<td>
<code>filter</code><br />
<Type text="Object" />
</td>
<td>
A <a href="/firewall/api/cf-filters/json-object/">Cloudflare Filter object</a> that contains an expression for evaluating this rule.
</td>
<td></td>
</tr>
<tr>
<td>
<code>action</code><br />
<Type text="String" />
</td>
<td>
The action to take when a request satisfies the filter expression for this rule.
</td>
<td>
Refer to <a href="/firewall/cf-firewall-rules/actions/">Firewall rules actions</a> for a list of supported values.
</td>
</tr>
<tr>
<td>
<code>priority</code><br />
<Type text="Number" />
</td>
<td>
Determines the order of evaluation for the rule relative to others. Lower values indicate greater priority. Rules without a value are evaluated last. For guidance, refer to <a href="#avoiding-priority-conflicts">Avoiding priority conflicts</a>.
</td>
<td>
<p>Read only</p>
<p>Maximum length: 32</p>
</td>
</tr>
<tr>
<td>
<code>paused</code><br />
<Type text="Boolean" />
</td>
<td>
Returns <code>true</code> when the rule is not active. Use <code>ref</code> to enable/disable the rule.
</td>
<td>
Default: <code>false</code>
</td>
</tr>
<tr>
<td>
<code>description</code><br />
<Type text="String" />
</td>
<td>An informative summary of the rule.</td>
<td>Maximum length: 500 characters</td>
</tr>
<tr>
<td>
<code>ref</code><br />
<Type text="String" />
</td>
<td>A short string for tagging rules.</td>
<td>Maximum length: 50 characters</td>
</tr>
</tbody>
</table>

## Avoiding priority conflicts

Priority plays a key role in configuring firewall rules. With Cloudflare Filters, it is possible to construct conflicting rules such as:

* Allow requests from the office IP range, and
* Block requests with a specific user agent.
- Allow requests from the office IP range, and
- Block requests with a specific user agent.

Requests from the office IP range using the user agent to block would trigger both rules, but we cannot both allow and block the request. To solve this problem, firewall rules follows a strict ordering depending on action and priority.

Cloudflare prioritizes rules in descending order, such that priority 1 is first and rules with no priority are last. For rules of equal priority, Cloudflare orders them by action according to their [order of precedence](/firewall/cf-firewall-rules/actions/#supported-actions). In the example above, if no priority is set, the rule `allow request from the office IP range` would apply because the *allow* action has a higher precedence than *block*.
Cloudflare prioritizes rules in descending order, such that priority 1 is first and rules with no priority are last. For rules of equal priority, Cloudflare orders them by action according to their [order of precedence](/firewall/cf-firewall-rules/actions/#supported-actions). In the example above, if no priority is set, the rule `allow request from the office IP range` would apply because the _allow_ action has a higher precedence than _block_.

To reduce the risk of unintended behavior, it is best to explicitly specify the desired priority for potentially conflicting rules.
Loading