Skip to content

Commit 8fe2e8a

Browse files
patriciasantaanapedrosousa
authored andcommitted
[API Shield] JWT Validation/Volumetric abuse detection rate limiting use case (cloudflare#23770)
* jwt validation use case * partial * punctuation * Apply suggestion from @pedrosousa Co-authored-by: Pedro Sousa <[email protected]> * Apply suggestion from @pedrosousa Co-authored-by: Pedro Sousa <[email protected]> * Apply suggestion from @pedrosousa Co-authored-by: Pedro Sousa <[email protected]> --------- Co-authored-by: Pedro Sousa <[email protected]>
1 parent 42c204b commit 8fe2e8a

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/content/docs/api-shield/security/jwt-validation/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66

77
---
88

9-
import { GlossaryTooltip, Steps, Tabs, TabItem } from "~/components"
9+
import { GlossaryTooltip, Steps, Tabs, TabItem, Render } from "~/components"
1010

1111
<GlossaryTooltip term="JSON web token (JWT)">JSON web tokens (JWT)</GlossaryTooltip> are often used as part of an authentication component on many web applications today. Since JWTs are crucial to identifying users and their access, ensuring the token’s integrity is important.
1212

@@ -50,7 +50,6 @@ To automatically keep your JWKS up to date when your identity provider refreshes
5050

5151
### Add a JWT validation rule
5252

53-
5453
<Tabs syncKey="dashNewNav">
5554
<TabItem label="Old dashboard">
5655
<Steps>
@@ -104,6 +103,8 @@ If you expect to migrate between two different identity providers, you must crea
104103

105104
API Shield will verify JSON Web Tokens regardless of whether or not they have the `Bearer` prefix.
106105

106+
<Render file="rate-limit-user" />
107+
107108
## Availability
108109

109110
JWT validation is available for all API Shield customers. Enterprise customers who have not purchased API Shield can preview [API Shield as a non-contract service](https://dash.cloudflare.com/?to=/:account/:zone/security/api-shield) in the Cloudflare dashboard or by contacting your account team.

src/content/docs/api-shield/security/volumetric-abuse-detection.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar:
77

88
---
99

10-
import { GlossaryTooltip, Steps } from "~/components"
10+
import { GlossaryTooltip, Steps, Render } from "~/components"
1111

1212
Cloudflare Volumetric Abuse Detection helps you set up a system of adaptive rate limiting.
1313

@@ -60,6 +60,10 @@ Refer to the [Rules documentation](https://developers.cloudflare.com/waf/rate-li
6060

6161
[Rate limit recommendations are available via the API](/api/resources/api_gateway/subresources/operations/methods/get/) if you would like to dynamically update rate limits over time.
6262

63+
## Special cases
64+
65+
<Render file="rate-limit-user" />
66+
6367
## Limitations
6468

6569
API Shield will always calculate recommendations when session identifiers are configured. To enable session-based rate limits, [subscribe to Advanced Rate Limiting](/waf/rate-limiting-rules/#availability).
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
{}
3+
4+
---
5+
6+
### Rate limit by user (JWT claim)
7+
8+
You can rate limit requests based on any claim inside of a JSON Web Token (JWT), such as:
9+
10+
- Registered claims like `aud` or `sub`
11+
- Custom claims like `userEmail`, including nested custom claims like `user.email`
12+
13+
Rate limiting based on JWT claim values will only work on valid JSON Web Tokens. If you do not block invalid JSON Web Tokens on your path, the [JWT claims will all be counted and possibly blocked](/waf/rate-limiting-rules/parameters/#missing-field-versus-empty-value) if high traffic is detected in the Point of Presence (PoP).
14+
15+
You must also count the JWT claim that uniquely identifies the user. If you select a claim that is the same for many of your users, their rate limits will all be counted together.
16+
17+
### Rate limit by user tier
18+
19+
If you offer multiple tiers on your website or application and you want to enforce rate limiting based on the tiers, such as:
20+
21+
- If `"aud": "free-tier"`, rate limit to five requests per minute.
22+
- If `"aud": "premium-tier"`, rate limit to 50 requests per minute.
23+
24+
You can follow the rate limiting rule example below:
25+
26+
```txt title="Example rule expression"
27+
(http.request.method eq "GET" and
28+
http.host eq "<YOUR_DOMAIN>" and
29+
http.request.uri.path matches "</EXAMPLE_PATH>" and
30+
lookup_json_string(http.request.jwt.claims["<JWT_TOKEN_CONFIGURATION_ID>"][0], "aud") eq "free-tier"
31+
```

0 commit comments

Comments
 (0)