Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

Rate Limiting Rules, Characteristics, Counting, and Mitigation

How Cloudflare WAF rate limiting rules match traffic, count requests per data center, and block or challenge abuse on login and API paths.

This page summarizes Cloudflare documentation on rate limiting rules: security rules in the http_ratelimit phase that cap how many matching requests a client may send in a time window, then apply an action such as block, challenge, or log. They sit on the edge in front of your origin and are the main way operators limit brute-force login traffic, API abuse, and scraping without writing application code for every endpoint.

Rate limiting rules allow you to define rate limits for requests matching an expression, and the action to perform when those rate limits are reached. Use rate limiting rules to prevent abuse of your websites and APIs — for example, to protect a login endpoint from brute-force attacks or to cap how many API calls a single client can make in a given time window.

— Cloudflare, Rate limiting rules

Rate limiting rules: what they protect and when you need them

Section titled “Rate limiting rules: what they protect and when you need them”

Rate limiting rules answer the question “how do I stop one IP, API key, or session from hammering this URL?” Typical triggers include credential stuffing on POST /login, machine-speed calls to REST or GraphQL APIs, form spam, and volumetric abuse that would exhaust origin CPU or bandwidth. Cloudflare’s security architecture groups rate limiting with other WAF controls: you define limits for traffic matching a Rules language expression and choose what happens when the rate is exceeded.

Request rates are not global. Counters run per Cloudflare data center (with cf.colo.id always part of the counter key), so distributed traffic may stay under threshold in each location even when aggregate volume is high. Rules also allow a short propagation delay before enforcement, so a burst may pass through before block or challenge applies—by design, not as a precise “exactly N requests to origin” gate.

Situation Typical rule focus
Login / OTP / password reset Tight limits on POST to auth paths; optional counting only on 401/403
Public API Per x-api-key, JWT claim, or path; separate rules for authenticated vs open endpoints
Forms and CMS login Per-IP limits above baseline traffic; challenge vs block by plan
GraphQL single endpoint Body or complexity-based limits (Enterprise Advanced Rate Limiting)

Rule parameters: expression, characteristics, period, and mitigation

Section titled “Rule parameters: expression, characteristics, period, and mitigation”

Every rate limiting rule combines a matching expression, an action, and a ratelimit configuration. The features overview lists the extra fields:

  • Characteristics — how Cloudflare groups requests into separate counters (for example ip.src, header x-api-key, path, cookie).
  • Period — seconds over which the rate is evaluated.
  • Requests per period — threshold that triggers the action.
  • Duration (mitigation timeout) — how long the action applies after the limit is hit (behavior differs for challenges on lower plans; see Rate limiting parameters).
  • Action behavior — default: apply the action for the full mitigation period; some Enterprise setups can throttle requests above the cap while allowing traffic under the limit.

Besides these two parameters, rate limiting rules require the following additional parameters: Characteristics … Period … Requests per period … Duration (or mitigation timeout) … Action behavior …

— Cloudflare, Rate limiting rules

Counting expression (Business and above): separate what increments the counter from what gets mitigated. Example pattern from Rate limiting best practices: count only failed logins (http.response.code in {401 403}) but block all traffic from the same IP on the host when a stricter rule fires. If you set a custom counting expression, it does not automatically include the match expression—you must combine both where needed (Rate limiting parameters).

Complexity-based limiting (Enterprise Advanced Rate Limiting): the origin returns a numeric score in a response header; Cloudflare sums scores per characteristic set instead of raw request counts (Request rate calculation).

Plan limits (rule count, fields, periods, characteristics) are summarized in the availability tables on Rate limiting rules and Features. Free plans get one rule and IP-only characteristics; Enterprise with Advanced Rate Limiting adds body, JSON, JA3/JA4, and custom expressions.

How request rate is calculated per data center

Section titled “How request rate is calculated per data center”

Request rate calculation explains counter semantics:

Cloudflare tracks request rates by maintaining separate counters for each unique combination of values in a rule’s characteristics.

— Cloudflare, Request rate calculation

Every rate limiting rule includes the Cloudflare data center ID (cf.colo.id) as a mandatory characteristic. … When creating rate limiting rules via API, you must include the cf.colo.id characteristic explicitly.

— Cloudflare, Request rate calculation

Implications for operators:

  • Two clients with the same API key but different IPs get separate counters when both IP and header are characteristics.
  • Do not use cf.colo.id in rule expressions; it is for counter scope only (Rate limiting parameters).
  • Optional Also apply rate limiting to cached assets / API requests_to_origin: when disabled, only origin-bound requests count toward the rate (Create a rate limiting rule in the dashboard).
  • Troubleshooting notes fail-open under infrastructure load (counters may not update) and hostname/Origin Rules interactions that can prevent counters from incrementing.

Legacy behavior from the previous version is similar in spirit: rates were also calculated per data center, with possible seconds of delay before enforcement.

Create a rate limiting rule in the dashboard (zone level)

Section titled “Create a rate limiting rule in the dashboard (zone level)”

For zone-level rules, use Security rules → Create rule → Rate limiting rules.

  1. Set Rule name and When incoming requests match (field builder or Rules language expression—for example URI path and method for /api/auth/login as in Discover and secure your API endpoints).

  2. Under With the same characteristics, choose counter keys (on Free, IP is fixed). Add headers or paths on higher plans per Rate limiting parameters.

  3. Optionally disable Also apply rate limiting to cached assets to count only origin traffic.

  4. Set When rate exceeds (requests and period). Tune using Find an appropriate rate limit (Enterprise Request rate analysis) or baseline traffic on Analytics.

  5. Choose Then take action (block, managed_challenge, log, etc.) and Duration. Deploy or save as draft.

Protect sensitive forms recommends Managed Challenge on Pro+ for forms (legitimate users can recover) and Block on Free. For login endpoints, Stop account takeover attacks suggests starting with Managed Challenge, then switching to Block after reviewing Security Events.

Account-level rate limiting rulesets (Enterprise)

Section titled “Account-level rate limiting rulesets (Enterprise)”

Enterprise customers can build a rate limiting ruleset once at account scope and deploy it to multiple zones (Rate limiting rulesets). Creation paths: dashboard or API.

Create and manage rate limiting rules via Rulesets API

Section titled “Create and manage rate limiting rules via Rulesets API”

The deprecated zone Rate Limiting API (GET/POST /zones/:zone_id/rate_limits, sunset 2025-06-15) is replaced by the Rulesets API and http_ratelimit phase (API deprecations, upgrade guide).

Zone workflow (Create a rate limiting rule via API):

  1. Get or create the zone entry point ruleset for phase http_ratelimit.
  2. Append a rule with ratelimit object; rate limiting rules must appear at the end of the rules list.
  3. Include cf.colo.id in characteristics alongside ip.src or other keys.

Minimal pattern (request properties):

curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$RULESET_ID/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"description": "My rate limiting rule",
"expression": "(http.request.uri.path matches \"^/api/\")",
"action": "block",
"ratelimit": {
"characteristics": ["cf.colo.id", "ip.src", "http.request.headers[\"x-api-key\"]"],
"period": 60,
"requests_per_period": 100,
"mitigation_timeout": 600
}
}'

Optional fields from the same doc: action_parameters.response for custom 403/429 bodies, requests_to_origin: true to ignore cached hits, and complexity rules with score_per_period and score_response_header_name. Terraform uses cloudflare_ruleset with phase = "http_ratelimit"—one ruleset resource per zone per phase.

Account ruleset creation is documented in Create a rate limiting ruleset via API (POST /accounts/$ACCOUNT_ID/rulesets with "phase": "http_ratelimit").

Credential stuffing — Stack rules with increasing severity; count failed auth responses where possible (Rate limiting best practices, Stop malicious bots). Example API login cap: 10 requests per minute per IP on /api/auth/login in Discover and secure your API endpoints.

Leaked credentials and account takeover — Combine cf.waf.credential_check.password_leaked or account takeover detections (cf.bot_management_detection_ids) in expressions with rate limiting on the Security rules page.

API keys and JWT tiers — Use header or JWT claim as characteristics (Rate limiting rule examples, JSON Web Tokens validation). API Shield can suggest per-operation limits when session identifiers and traffic data are available (Get started with API Shield).

Threat intelligence — Stricter limits on flagged IPs, e.g. any(cf.intel.ip.datasets[*] == "ddos") on /api/ paths (Example rules).

Stacking rules — Multiple rules on the same path with different characteristics or thresholds can track dynamic abuse (Configurations learning path).

Path expressions should match how your app normalizes URLs; mismatched trailing slashes or query strings cause missed matches (see legacy troubleshooting patterns that still illustrate URL matching pitfalls).

Section titled “Plan limits, HTTP 429, and related rate limit products”

Visitor-facing 429 — When a rate limiting rule blocks, Cloudflare can return HTTP 429; site owners see events in Rate Limiting Analytics (Error 429). Challenge Passage does not apply to rate limiting rules (Challenge Passage).

Cloudflare API quotas (managing rules via api.cloudflare.com, not edge rules on your zone) are separate: for example 1,200 Client API requests per 5 minutes per user (Rate limits). GraphQL Analytics defaults to 300 queries per 5 minutes per user; optional account-based limits use header X-Rate-Limit-Type: account-based for per-account and per-zone budgets (Account-based rate limiting, Limits).

Workers Rate Limiting binding — In-worker limit() counters are approximate and per location, backed by similar infrastructure but intended for app logic after the Worker runs (Rate Limiting binding). Strict global quotas may need Durable Objects, as described there.

Other Cloudflare products mention “rate limiting” with different meanings: AI Search public endpoints (120 requests per minute default, Public endpoint settings), AI Gateway fixed vs sliding windows (AI Gateway rate limiting), cache purge token buckets (Purge cache), Advanced Network Firewall packet/bit policies (beta, packet filtering guide). Those are not WAF http_ratelimit rules unless you explicitly configure them.

  1. In the Cloudflare dashboard, open Analytics → Events, filter Action equals Block (or challenge) and Service equals Rate limiting, and confirm whether blocked clients are abusive or legitimate.

  2. For Enterprise zones, use the Request rate analysis tab per Find an appropriate rate limit to compare your rule threshold against live rate distributions before or after changes.

  3. Trigger a controlled burst against a test path (or use Log action first per Find an appropriate rate limit) and confirm the expected block, challenge, or custom response; visitors should see HTTP 429 when blocked, as described in Error 429.

  4. If rules never fire despite obvious abuse, review Troubleshooting rate limiting rules for Origin Rule hostname issues, fail-open behavior, and per-data-center counting.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.