Skip to content

Commit 056b1af

Browse files
committed
[WAF] RL: Add complexity score diagram and example
1 parent b491295 commit 056b1af

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed
90 KB
Loading

src/content/docs/waf/rate-limiting-rules/request-rate.mdx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Consider the following configuration for a rate limiting rule:
5555

5656
- _Data center ID_ (included by default when creating the rule in the dashboard)
5757
- _IP_
58-
- _Headers_ > `x-api-key`
58+
- _Header value of_ > `x-api-key`
5959

6060
</Example>
6161

@@ -94,7 +94,7 @@ Consider the following configuration for a rate limiting rule. The rule counting
9494

9595
- _Data center ID_ (included by default when creating the rule in the dashboard)
9696
- _IP_
97-
- _Headers_ > `x-api-key`
97+
- _Header value of_ > `x-api-key`
9898

9999
**Increment counter when**:
100100
`http.request.uri.path eq "/form" and http.response.code eq 400`
@@ -135,4 +135,44 @@ Cloudflare keeps counters with the total score of all requests with the same val
135135

136136
If the origin server does not provide the HTTP response header with a score value or if the score value is outside of the allowed range, the corresponding rate limiting counter will not be updated.
137137

138-
For an example of a complexity-based rate limiting rule, refer to [Rule examples](/waf/rate-limiting-rules/use-cases/#example-4).
138+
### Example C
139+
140+
Consider the following configuration for a rate limiting rule. When there is a rule match, the complexity score counter will increase based on the value in the `x-score` response header provided by the origin server.
141+
142+
<Example>
143+
144+
**_Rate limiting rule #3_**
145+
146+
**If incoming requests match**:<br />
147+
`(http.request.uri.path eq "/graphql")`
148+
149+
**With the same value of** (characteristics):
150+
151+
- _Data center ID_ (included by default when creating the rule in the dashboard)
152+
- _Header value of_ > `x-api-key`
153+
154+
**When rate exceeds**: _Complexity based_
155+
156+
- Score per period: `400`
157+
- Period: _1 minute_
158+
- Response header name: `x-score`
159+
160+
**Choose action**: _Block_
161+
162+
**With the following behavior**: _Block for the selected duration_
163+
164+
**Duration** (mitigation timeout): _10 minutes_
165+
166+
</Example>
167+
168+
The following diagram shows how Cloudflare handles four incoming requests received during a 1-minute period in the context of the above rate limiting rule.
169+
170+
![Rate limiting example with four requests where the rate limiting rule is configured to take into account the complexity score provided in the "x-score" HTTP header. For details, keep reading.](~/assets/images/waf/custom-rules/rate-limiting-example-complexity-based.png)
171+
172+
Since request 1 matches the rule expression, the rate limiting rule is evaluated. The origin responds with a `200` status code and a complexity score of `100` in the `x-score` HTTP response header. Cloudflare creates a request counter for the values of the characteristics in the context of the rate limiting rule, and sets this counter to `100`.
173+
174+
Request 2 matches the rule expression and therefore Cloudflare evaluates the rate limiting rule. The request counter for the characteristics values is still within the maximum score per period. The origin responds with a `200` status code and the request counter is increased by `200`. The current complexity score for the request is now `300`.
175+
176+
Request 3 matches the rule expression and therefore Cloudflare evaluates the rate limiting rule. The request counter for the characteristics values is still within the maximum score per period. The origin responds with a `200` status code and the request counter is increased by `150`. The current complexity score for the request is now `450`.
177+
178+
Request 4 matches the rule expression and therefore Cloudflare evaluates the rate limiting rule. The request is no longer within the maximum score per period defined in the rule (the counter has the value `450` and the maximum score is `400`). Cloudflare applies the action defined in the rate limiting rule configuration, blocking request 4 and any later requests that match the rate limiting rule for ten minutes.

0 commit comments

Comments
 (0)