Skip to content

Commit f6bf031

Browse files
author
Pedro Sousa
authored
[WAF] Update HTTP request headers use case (cloudflare#20331)
1 parent 0d94927 commit f6bf031

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/content/docs/waf/custom-rules/use-cases/require-specific-headers.mdx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ title: Require specific HTTP headers
55

66
Many organizations qualify traffic based on the presence of specific HTTP request headers. Use the Rules language [HTTP request header fields](/ruleset-engine/rules-language/fields/reference/?field-category=Headers&search-term=http.request) to target requests with specific headers.
77

8-
This example uses the `http.headers.names` field to look for the presence of an `X-CSRF-Token` header. The [`lower()`](/ruleset-engine/rules-language/functions/#lower) transformation function converts the value to lowercase so that the expression is case insensitive.
8+
## Example 1: Require presence of HTTP header
99

10-
When the `X-CSRF-Token` header is missing, Cloudflare blocks the request:
10+
This example uses the [`http.request.headers.names`](/ruleset-engine/rules-language/fields/reference/http.request.headers.names/) field to look for the presence of an `X-CSRF-Token` header. The [`lower()`](/ruleset-engine/rules-language/functions/#lower) transformation function converts the header name to lowercase so that the expression is case-insensitive.
11+
12+
When the `X-CSRF-Token` header is missing, Cloudflare blocks the request.
1113

1214
- **Expression**: `not any(lower(http.request.headers.names[*])[*] eq "x-csrf-token") and (http.request.full_uri eq "https://www.example.com/somepath")`
1315
- **Action**: _Block_
16+
17+
## Example 2: Require HTTP header with a specific value
18+
19+
This example uses the [`http.request.headers`](/ruleset-engine/rules-language/fields/reference/http.request.headers/) field to look for the presence of the `X-Example-Header` header and to get its value (if any). The keys in the `http.request.headers` field, corresponding to HTTP header names, are in lowercase.
20+
21+
When the `X-Example-Header` header is missing or it does not have the value `example-value`, Cloudflare blocks the request.
22+
23+
- **Expression**: `not any(http.request.headers["x-example-header"][*] eq "example-value") and (http.request.uri.path eq "/somepath")`
24+
- **Action**: _Block_
25+
26+
In this example the header name is case-insensitive, but the header value is case-sensitive.

0 commit comments

Comments
 (0)