|
8 | 8 | content: Configure WAF custom rules with Terraform |
9 | 9 | --- |
10 | 10 |
|
11 | | -import { Render } from "~/components"; |
| 11 | +import { Render, GlossaryTooltip } from "~/components"; |
12 | 12 |
|
13 | 13 | This page provides examples of creating WAF custom rules in a zone or account using Terraform. The examples cover the following scenarios: |
14 | 14 |
|
15 | 15 | - Zone-level configurations: |
16 | | - |
17 | 16 | - [Add a custom rule to a zone](#add-a-custom-rule-to-a-zone) |
18 | 17 | - [Add a custom rule challenging requests with leaked credentials](#add-a-custom-rule-challenging-requests-with-leaked-credentials) |
19 | | - |
| 18 | + - [Add a custom rule blocking malicious uploads](#add-a-custom-rule-blocking-malicious-uploads) |
20 | 19 | - Account-level configurations: |
21 | | - |
22 | 20 | - [Create and deploy a custom ruleset](#create-and-deploy-a-custom-ruleset) |
23 | 21 | - [Add a custom rule checking for exposed credentials](#add-a-custom-rule-checking-for-exposed-credentials) |
24 | 22 |
|
@@ -88,6 +86,33 @@ resource "cloudflare_ruleset" "zone_custom_firewall_leaked_creds" { |
88 | 86 |
|
89 | 87 | For more information on configuring custom detection locations, refer to the [Terraform example](/waf/detections/leaked-credentials/get-started/#4-optional-configure-a-custom-detection-location) in the WAF documentation. |
90 | 88 |
|
| 89 | +### Add a custom rule blocking malicious uploads |
| 90 | + |
| 91 | +:::note |
| 92 | +For more information on enabling malicious uploads detection using Terraform, refer to the [malicious uploads detection](/waf/detections/malicious-uploads/get-started/#1-turn-on-the-detection) documentation. |
| 93 | +::: |
| 94 | + |
| 95 | +This example adds a custom rule that blocks requests with one or more <GlossaryTooltip term="content object">content objects</GlossaryTooltip> considered malicious by using one of the [content scanning fields](/waf/detections/malicious-uploads/#content-scanning-fields) in the rule expression. |
| 96 | + |
| 97 | +```tf |
| 98 | +resource "cloudflare_ruleset" "zone_custom_firewall_malicious_uploads" { |
| 99 | + zone_id = "<ZONE_ID>" |
| 100 | + name = "Phase entry point ruleset for custom rules in my zone" |
| 101 | + description = "" |
| 102 | + kind = "zone" |
| 103 | + phase = "http_request_firewall_custom" |
| 104 | +
|
| 105 | + rules { |
| 106 | + ref = "block_malicious_uploads" |
| 107 | + description = "Block requests uploading malicious content objects" |
| 108 | + expression = "(cf.waf.content_scan.has_malicious_obj and http.request.uri.path eq \"/upload.php\")" |
| 109 | + action = "block" |
| 110 | + } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +For more information on configuring custom scan expressions, refer to the [Terraform example](/waf/detections/malicious-uploads/get-started/#4-optional-configure-a-custom-scan-expression) in the WAF documentation. |
| 115 | + |
91 | 116 | ## Account-level configurations |
92 | 117 |
|
93 | 118 | ### Create and deploy a custom ruleset |
|
0 commit comments