Skip to content

Commit fe5be3f

Browse files
authored
[Rules] Snippets updates (#22303)
* Update IP lists anchor name * Mention WAF attack score * Update two snippet examples with rules also
1 parent c209e9b commit fe5be3f

File tree

17 files changed

+69
-36
lines changed

17 files changed

+69
-36
lines changed

src/content/docs/ddos-protection/managed-rulesets/http/configure-api.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Use overrides to configure the HTTP DDoS Attack Protection managed ruleset. Over
2222

2323
Overrides can have a ruleset, tag, or rule scope. Tag and rule configurations have greater priority than ruleset configurations.
2424

25-
You can create overrides at the zone level and at the account level. Account-level overrides allow you to apply the same override to several zones in your account with a single rule. For example, you can use an account-level override to lower the sensitivity of a specific managed ruleset rule or exclude an [IP list](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists) for multiple zones. However, if a given zone has overrides for the HTTP DDoS Attack Protection managed ruleset, the account-level overrides will not be evaluated for that zone.
25+
You can create overrides at the zone level and at the account level. Account-level overrides allow you to apply the same override to several zones in your account with a single rule. For example, you can use an account-level override to lower the sensitivity of a specific managed ruleset rule or exclude an [IP list](/waf/tools/lists/custom-lists/#ip-lists) for multiple zones. However, if a given zone has overrides for the HTTP DDoS Attack Protection managed ruleset, the account-level overrides will not be evaluated for that zone.
2626

2727
:::caution[Important]
2828

@@ -141,7 +141,7 @@ For more information on defining overrides for managed rulesets using the Rulese
141141

142142
### Account-level configuration example
143143

144-
The following `PUT` example creates a new phase ruleset (or updates the existing one) for the `ddos_l7` phase at the account level. The example defines a single rule override for requests coming from IP addresses in the `allowlisted_ips` [IP list](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists), with the following configuration:
144+
The following `PUT` example creates a new phase ruleset (or updates the existing one) for the `ddos_l7` phase at the account level. The example defines a single rule override for requests coming from IP addresses in the `allowlisted_ips` [IP list](/waf/tools/lists/custom-lists/#ip-lists), with the following configuration:
145145

146146
- The rule with ID `<MANAGED_RULESET_RULE_ID>`, belonging to the HTTP DDoS Attack Protection managed ruleset (with ID `<MANAGED_RULESET_ID>`), will have an `eoff` (_Essentially Off_) sensitivity level and it will perform a `log` action.
147147

src/content/docs/firewall/cf-dashboard/rule-preview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ In this screenshot, a rule that matches all User-Agents that contain the string
3636

3737
**Rule Preview does not take into account other firewall rules** that you have already configured. In effect, Rule Preview tests a single firewall rule in isolation. Security events or any other rules with a higher priority that may have blocked or challenged a request are ignored.
3838

39-
**You cannot test firewall rules that reference [IP lists](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists)**.
39+
**You cannot test firewall rules that reference [IP lists](/waf/tools/lists/custom-lists/#ip-lists)**.
4040

4141
**Cloudflare does not store the entirety of requests, so only a limited number of fields are available to Rule Preview**. The table below lists the fields that Rule Preview supports (green cells), broken down by operator. Fields and operators that are not supported are not included in this table.

src/content/docs/firewall/cf-firewall-rules/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Cloudflare Firewall Rules is a flexible and intuitive framework for filtering HT
1616

1717
<Render file="deprecation-notice" />
1818

19-
In a firewall rule you define an [expression](/ruleset-engine/rules-language/expressions/) that tells Cloudflare what to look for in a request, and specify the appropriate [action](/firewall/cf-firewall-rules/actions/) to take when those conditions are met. Expressions can reference [IP lists](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists) - groups of IP addresses that you can reference collectively by name.
19+
In a firewall rule you define an [expression](/ruleset-engine/rules-language/expressions/) that tells Cloudflare what to look for in a request, and specify the appropriate [action](/firewall/cf-firewall-rules/actions/) to take when those conditions are met. Expressions can reference [IP lists](/waf/tools/lists/custom-lists/#ip-lists) - groups of IP addresses that you can reference collectively by name.
2020

2121
To write firewall rule expressions, use the [Rules language](/ruleset-engine/rules-language/), a powerful expression language inspired in the Wireshark Display Filter language.

src/content/docs/magic-firewall/about/list-types.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The threat intelligence feed categories are described in [Managed IP Lists](/waf
1111

1212
## IP lists
1313

14-
Use [IP lists](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists) to group services in networks, like web servers, or for lists of known bad IP addresses to make managing good network endpoints easier. IP lists are helpful for users with very expansive firewall rules with many IP lists. By default, you can add up to 10,000 IPs across all lists. Refer to [Use an IP list](/magic-firewall/how-to/add-rules/#use-an-ip-list) to check an example of how to use an IP list.
14+
Use [IP lists](/waf/tools/lists/custom-lists/#ip-lists) to group services in networks, like web servers, or for lists of known bad IP addresses to make managing good network endpoints easier. IP lists are helpful for users with very expansive firewall rules with many IP lists. By default, you can add up to 10,000 IPs across all lists. Refer to [Use an IP list](/magic-firewall/how-to/add-rules/#use-an-ip-list) to check an example of how to use an IP list.
1515

1616
## Geo-blocking
1717

src/content/docs/magic-firewall/best-practices/extended-ruleset.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Rule 10 in the example ruleset below is acting as a catch-all to block all traff
7171

7272
Follow the best practices for internal routers or firewall interface IP addresses on your MT prefixes below.
7373

74-
1. Create [an IP list](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists), **Internal routers** for example, with your IP addresses.
74+
1. Create [an IP list](/waf/tools/lists/custom-lists/#ip-lists), **Internal routers** for example, with your IP addresses.
7575
2. Block ICMP if it is not needed.
7676
3. Permit GRE/ESP as needed if the devices have GRE/IPsec tunnels via the Internet.
7777

@@ -101,7 +101,7 @@ Where possible, permit the required destination IP addresses and ports for web s
101101

102102
The following is an example of suggested rules, but you should only make changes based on your specific requirements. For example, if you are not proxied by Cloudflare Layer 7 protection and you expect traffic sourced from the web towards your web servers:
103103

104-
1. Create [an IP list](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists), **web servers** for example, to list IP addresses for your web servers.
104+
1. Create [an IP list](/waf/tools/lists/custom-lists/#ip-lists), **web servers** for example, to list IP addresses for your web servers.
105105
2. Permit traffic for the web server traffic inbound from the Internet.
106106
3. Permit traffic for the infrastructure or client traffic flows from the Internet, for example DNS and NTP.
107107
4. Block all other traffic destined for the web server IP addresses.

src/content/docs/magic-firewall/how-to/use-rules-list.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ head:
88
content: Define an IP list
99
---
1010

11-
[IP lists](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists) are a part of Cloudflare's custom lists. Custom lists contain one or more items of the same type — IP addresses, hostnames or ASNs — that you can reference in rule expressions.
11+
[IP lists](/waf/tools/lists/custom-lists/#ip-lists) are a part of Cloudflare's custom lists. Custom lists contain one or more items of the same type — IP addresses, hostnames or ASNs — that you can reference in rule expressions.
1212

1313
IP lists are defined at the account level and can be used to match against `ip.src` and `ip.dst` fields. Currently, Magic Firewall only supports IPv4 addresses in these lists, not IPv6.
1414

src/content/docs/rules/snippets/examples/maintenance.mdx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,33 @@ title: Maintenance page
1212
description: Serve a custom maintenance page instead of fetching content from the origin server or cache. Ideal for downtime notifications, planned maintenance, or emergency messages.
1313
---
1414

15+
## Snippet code
16+
1517
```js
1618
// Define your customizable inputs
1719
const statusCode = 503;
1820
const title = "We'll Be Right Back!";
19-
const message = "Our site is currently undergoing scheduled maintenance. We’re working hard to bring you a better experience. Thank you for your patience and understanding.";
21+
const message =
22+
"Our site is currently undergoing scheduled maintenance. We’re working hard to bring you a better experience. Thank you for your patience and understanding.";
2023
const estimatedTime = "1 hour";
2124
const contactEmail = "[email protected]";
2225
const contactPhone = "+1 234 567 89";
2326

2427
export default {
25-
async fetch(request) {
26-
// Serve the maintenance page as a response
27-
return new Response(generateMaintenancePage(), {
28-
status: statusCode,
29-
headers: {
30-
"Content-Type": "text/html",
31-
"Retry-After": "3600", // Suggest retry after 1 hour
32-
},
33-
});
34-
},
28+
async fetch(request) {
29+
// Serve the maintenance page as a response
30+
return new Response(generateMaintenancePage(), {
31+
status: statusCode,
32+
headers: {
33+
"Content-Type": "text/html",
34+
"Retry-After": "3600", // Suggest retry after 1 hour
35+
},
36+
});
37+
},
3538
};
3639

3740
function generateMaintenancePage() {
38-
return `
41+
return `
3942
<!DOCTYPE html>
4043
<html lang="en">
4144
<head>
@@ -105,3 +108,19 @@ function generateMaintenancePage() {
105108
`;
106109
}
107110
```
111+
112+
## Snippet rule
113+
114+
Configure a custom filter expression:
115+
116+
| Field | Operator | Value |
117+
| ----------------- | -------------- | ----------- |
118+
| IP Source Address | is not in list | `admin_ips` |
119+
120+
If you are using the Expression Editor, enter the following expression:
121+
122+
```txt
123+
(not ip.src in $admin_ips)
124+
```
125+
126+
The [IP list](/waf/tools/lists/custom-lists/#ip-lists) `admin_ips` was previously created and contains the list of IP addresses of the site administrators, which will be able to access the site during the maintenance period.

src/content/docs/rules/snippets/examples/slow-suspicious-requests.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
type: example
33
summary: Define a delay to be used when incoming requests match a rule you
4-
consider suspicious.
4+
consider suspicious based on the bot score.
55
goal:
66
- Other
77
operation:
@@ -11,9 +11,11 @@ products:
1111
pcx_content_type: example
1212
title: Slow down suspicious requests
1313
description: Define a delay to be used when incoming requests match a rule you
14-
consider suspicious.
14+
consider suspicious based on the bot score.
1515
---
1616

17+
## Snippet code
18+
1719
```js
1820
export default {
1921
async fetch(request) {
@@ -30,3 +32,17 @@ export default {
3032
},
3133
};
3234
```
35+
36+
## Snippet rule
37+
38+
Configure a custom filter expression:
39+
40+
| Field | Operator | Value |
41+
| --------- | --------- | ----- |
42+
| Bot Score | less than | `10` |
43+
44+
If you are using the Expression Editor, enter the following expression:
45+
46+
```txt
47+
(cf.bot_management.score lt 10)
48+
```

src/content/docs/rules/snippets/how-it-works.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ sidebar:
66
head:
77
- tag: title
88
content: How it works
9-
109
---
1110

1211
Cloudflare Snippets are executed based on rules defined within your zone. Here is how the process works:
1312

1413
## Request evaluation
1514

16-
For each incoming request, Cloudflare evaluates the expression of every Snippet Rule defined in the zone. The evaluation checks for a match based on various request properties (such as bot score, country of origin, cookies).
15+
For each incoming request, Cloudflare evaluates the expression of every Snippet Rule defined in the zone. The evaluation checks for a match based on various request properties (such as bot score, WAF attack score, country of origin, and cookies).
1716

1817
## Snippet execution
1918

src/content/docs/rules/transform/response-header-modification/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ You can create a response header transform rule [in the dashboard](/rules/transf
5555

5656
- You cannot modify the value of certain headers such as `server`, `eh-cache-tag`, or `eh-cdn-cache-control`.
5757

58-
- Currently you cannot reference [IP lists](/waf/tools/lists/custom-lists/#lists-with-ip-addresses-ip-lists) in expressions of Response Header Transform Rules.
58+
- Currently you cannot reference [IP lists](/waf/tools/lists/custom-lists/#ip-lists) in expressions of Response Header Transform Rules.
5959

6060
- The HTTP response header removal operation will remove all response headers with the provided name.
6161

0 commit comments

Comments
 (0)