Rate limiting best practices
Last updated Oct 23, 2026 The following sections cover typical rate limiting configurations for common use cases. You can combine the provided example rules and adjust them to your own scenario.
Path matching and URL normalization
Path-based examples on this page assume that Cloudflare and your origin application interpret request paths consistently. Origin servers and frameworks may normalize or decode paths differently. As a result, alternative path representations could reach the same endpoint without matching the rule. Review your URL normalization settings and test all path representations accepted by your application.
The main use cases for rate limiting are the following:
- Enforce granular access control to resources. Includes access control based on criteria such as user agent, IP address, referrer, host, country, and world region.
- Protect against credential stuffing and account takeover attacks.
- Limit the number of operations performed by individual clients. Includes preventing scraping by bots, accessing sensitive data, bulk creation of new accounts, and programmatic buying in ecommerce platforms.
- Protect REST APIs from resource exhaustion (targeted DDoS attacks) and resources from abuse in general.
- Protect GraphQL APIs by preventing server overload and limiting the number of operations.
Enforcing granular access control
Limit by user agent
A common use case is to limit the rate of requests performed by individual user agents. The following example rule allows a mobile app to perform a maximum of 100 requests in 10 minutes. You could also create a separate rule limiting the rate for desktop browsers.
| Setting | Value |
|---|---|
| Matching criteria | User Agent equals MobileApp |
| Expression | http.user_agent eq "MobileApp" |
| Counting characteristics | IP |
| Rate (Requests / Period) | 100 requests / 10 minutes |
| Action | Managed Challenge |
Limit reuse of a single cf_clearance cookie
After a visitor successfully passes a Managed Challenge, Cloudflare issues a cf_clearance cookie to identify them as verified. However, malicious actors may attempt to reuse or share a single valid clearance identity across multiple requests or devices to bypass additional challenges.
This rate limiting rule helps mitigate such abuse by restricting how many requests can be made with the same Clearance UUID within a defined period. The UUID remains stable when Cloudflare refreshes the encrypted cookie value, so JavaScript Detections and Precursor updates do not reset the request counter.
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /checkout |
| Expression | http.request.uri.path eq "/checkout" |
| Counting characteristics | Clearance UUID |
| Counting expression | http.request.clearance.uuid ne "" |
| Rate (Requests / Period) | 100 requests / 10 minutes |
| Action | Block |
Requests without a valid clearance cookie are excluded from this counter. To rate limit those requests, create a separate rule using another characteristic, such as IP.
Allow specific IP addresses or ASNs
Another use case when controlling access to resources is to exclude or include IP addresses or Autonomous System Numbers (ASNs) from a rate limiting rule.
The following example rule allows up to 10 requests per minute from the same IP address doing a GET request for /status, as long as the visitor's IP address is not included in the partner_ips IP list.
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /status and Request Method equals GET and IP Source Address is not in list partner_ips |
| Expression | http.request.uri.path eq "/status" and http.request.method eq "GET" and not ip.src in $partner_ips |
| Counting characteristics | IP |
| Rate (Requests / Period) | 10 requests / 1 minute |
| Action | Managed Challenge |
Limit by referrer
Some applications receive requests originated by other sources (for example, used by advertisements linking to third-party pages). You may wish to limit the number of requests generated by individual referrer pages to manage quotas or avoid indirect DDoS attacks.
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /status and Request Method equals GET |
| Expression | http.request.uri.path eq "/status" and http.request.method eq "GET" |
| Counting characteristics | Header (Referer) <sup>1</sup> |
| Rate (Requests / Period) | 100 requests / 10 minutes |
| Action | Block |
This example rule requires Advanced Rate Limiting.
Limit by destination host
SaaS applications or customers using Cloudflare SSL for SaaS might have thousands of hosts under the same zone, which makes creating individual rules per host impractical. To overcome this, you can create a rate limiting rule that uses the host as a counting characteristic.
The following example rule will track the rate of requests to the /login endpoint for each host:
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /login and Request Method equals GET |
| Expression | http.request.uri.path eq "/login" and http.request.method eq "GET" |
| Counting characteristics | IP and Host |
| Rate (Requests / Period) | 10 requests / 10 minutes |
| Action | Block |
This example rule requires Advanced Rate Limiting.
Protecting against credential stuffing
A typical use case of rate limiting is to protect a login endpoint against attacks such as credential stuffing ↗︎. The following example contains three different rate limiting rules with increasing penalties to manage clients making too many requests.
Rule #1
| Setting | Value |
|---|---|
| Matching criteria | Hostname equals example.com and URI Path equals /login and Request Method equals POST |
| Expression | http.host eq "example.com" and http.request.uri.path eq "/login" and http.request.method eq "POST" |
| Counting characteristics | IP |
| Increment counter when | URI Path equals /login and Method equals POST and Response code is in (401, 403) |
| Counting expression | http.request.uri.path eq "/login" and http.request.method eq "POST" and http.response.code in {401 403} |
| Rate (Requests / Period) | 4 requests / 1 minute |
| Action | Managed Challenge |
Rule #2
| Setting | Value |
|---|---|
| Matching criteria | Hostname equals example.com and URI Path equals /login and Request Method equals POST |
| Expression | http.host eq "example.com" and http.request.uri.path eq "/login" and http.request.method eq "POST" |
| Counting characteristics | IP |
| Increment counter when | URI Path equals /login and Request Method equals POST and Response Status Code is in (401, 403) |
| Counting expression | http.request.uri.path eq "/login" and http.request.method eq "POST" and http.response.code in {401 403} |
| Rate (Requests / Period) | 10 requests / 10 minutes |
| Action | Managed Challenge |
Rule #3
| Setting | Value |
|---|---|
| Matching criteria | Host equals example.com |
| Expression | http.host eq "example.com" |
| Counting characteristics | IP |
| Increment counter when | URI Path equals /login and Request Method equals POST and Response Status Code is in (401, 403) |
| Counting expression | http.request.uri.path eq "/login" and http.request.method eq "POST" and http.response.code in {401 403} |
| Rate (Requests / Period) | 20 requests / 1 hour |
| Action | Block for 1 day |
These example rules require a Business plan or above.
Rule #1 allows up to four requests per minute, after which a Managed Challenge is triggered. This configuration allows legitimate customers a few attempts to remember their password. If an automated actor makes several requests, that client will likely be blocked by an unsolved Managed Challenge. On the other hand, if a human gets and passes the challenge when reaching rule #1's rate limit, rule #2 will provide the next level of protection, allowing for up to 10 requests over the next 10 minutes. For clients exceeding this second threshold, rule #3 (the most severe) will apply, blocking the client for one day.
These three rules have a counting expression separate from the rule expression (also known as mitigation expression). When you configure a separate counting expression, the matching criteria will only be used when an action is triggered. In the counting expression you can include conditions based on the HTTP response status code and HTTP response headers, therefore integrating rate limiting with your backend logic.
You can also decide to have two different expressions — a counting expression and a rule/mitigation expression — to define:
- The requests used to compute the rate.
- The requests actually acted upon.
For example, rule #3 computes the rate considering POST requests to /login that returned a 401 or 403 HTTP status code. However, when the rate limit is exceeded, Cloudflare blocks every request to the example.com host generated by the same IP. For more information on counting expressions, refer to Request rate calculation.
Configuring additional protection
Login endpoints are also commonly protected against the use of exposed credentials and bot abuse.
Protect OTP and verification endpoints
One-time password (OTP) and verification endpoints (such as /api/otp/validate or /account/verify) are frequent targets for brute force attacks. These endpoints are particularly sensitive because attackers attempt large volumes of requests with different codes to guess a valid OTP.
When configuring rate limiting for these endpoints, follow these guidelines:
- Match the exact URI path: The rule expression must match the path that receives attack traffic. Verify the path in analytics before creating the rule. A rule targeting
/validate/otpwill not match requests to/api/otp/validate. - Use response-based counting: Count only requests that return error responses (such as
401or403) to avoid rate limiting legitimate users who submit valid codes. - Scope geographic restrictions appropriately: If you restrict by country, verify that attack traffic originates from all the countries you observe in analytics, not just one.
The following example rule protects an OTP validation endpoint by counting only failed attempts:
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /api/otp/validate and Request Method equals POST |
| Expression | http.request.uri.path eq "/api/otp/validate" and http.request.method eq "POST" |
| Counting characteristics | IP |
| Increment counter when | URI Path equals /api/otp/validate and Request Method equals POST and Response Status Code is in (401, 403) |
| Counting expression | http.request.uri.path eq "/api/otp/validate" and http.request.method eq "POST" and http.response.code in {401 403} |
| Rate (Requests / Period) | 5 requests / 1 minute |
| Action | Block for 10 minutes |
The above example rule requires a Business plan or higher.
If your OTP endpoint returns 200 for both valid and invalid codes (with the result in the response body), use request-based counting with a lower threshold instead:
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /api/otp/validate and Request Method equals POST |
| Expression | http.request.uri.path eq "/api/otp/validate" and http.request.method eq "POST" |
| Counting characteristics | IP |
| Rate (Requests / Period) | 10 requests / 1 minute |
| Action | Managed Challenge |
Limiting the number of operations
You can use rate limiting to limit the number of operations performed by a client. The exact rule providing this protection will depend on your application. The following examples address content scraping ↗︎ via query string parameters or JSON body.
Prevent content scraping (via query string)
In this example, clients perform operations (such as looking up prices and adding to basket) on an ecommerce website using different query string parameters. For example, a typical request sent by a client could be similar to the following:
GET https://store.com/merchant?action=lookup_price&product_id=215
Cookie: session_id=12345
Your security team might want to consider setting up a limit on the number of times a client can lookup prices to prevent bots — which may have eluded Cloudflare Bot Management — from scraping the store's entire catalog.
Rule #1
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /merchant and URI Query String contains action=lookup_price |
| Expression | http.request.uri.path eq "/merchant" and http.request.uri.query contains "action=lookup_price" |
| Counting characteristics | IP |
| Rate (Requests / Period) | 10 requests / 2 minutes |
| Action | Managed Challenge |
Rule #2
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /merchant and URI Query String contains action=lookup_price |
| Expression | http.request.uri.path eq "/merchant" and http.request.uri.query contains "action=lookup_price" |
| Counting characteristics | IP |
| Rate (Requests / Period) | 20 requests / 5 minute |
| Action | Block |
These two rate limiting rules match requests performing a selected action (look up price, in this example) and use IP as the counting characteristic. Similarly to the previous /login example, the two rules will help reduce false positives in case of persistent (but legitimate) visitors.
To limit the lookup of a specific product_id via query string parameter, you could add that specific query parameter as a counting characteristic, so that the rate is calculated based on all the requests, regardless of the client. The following example rule limits the number of lookups for each product_id to 50 requests in 10 seconds.
| Setting | Value |
|---|---|
| Matching criteria | URI Path equals /merchant |
| Expression | http.request.uri.path eq "/merchant" |
| Counting characteristics | Query (product_id) |
| Rate (Requests / Period) | 50 requests / 10 seconds |
| Action | Block |
This example rule requires Advanced Rate Limiting.
You could follow the same pattern of rate limiting rules to protect applications handling reservations and bookings.
Prevent content scraping (via body)
Consider an application that handles the operation and its parameters through the request body in JSON format. For example, the lookup_price operation could look like the following:
