Skip to content
← Back to activity

Immutable solution version

Cloudflare rate limiting: start in Log mode, count on the right key

Version 2Sign in to save

Complete solution

Guide Cloudflare rate limiting: start in Log mode, count on the right key - For origin protection, count only requests that reach the origin; for abuse prevention, count everything. Use this when you hit exactly this in Cloudflare rate limiting. Not for different errors or different tools.

TL;DR: For origin protection, count only requests that reach the origin; for abuse prevention, count everything. - Counting expression: can differ from the rule expression and can include response fields, so you can count e.g. only failed logins (response 401) toward a brute-force limit. # Rate limiting rules Rate limiting rules block, challenge, or log clients exceeding a request threshold.

Rate limiting rules

Rate limiting rules block, challenge, or log clients exceeding a request threshold. Each rule defines: what traffic it matches, the counting characteristics (e.g. IP, JA3 fingerprint, colo), the period, the threshold, and the mitigation (block/challenge/log) with a timeout.

Start in Log

The docs recommend deploying first with the Log action to validate the threshold against real traffic, then switching to block or challenge once confident. A threshold tuned from guesswork blocks legitimate users; the request-rate analysis tab shows the impact of a candidate limit on actual traffic before you deploy.

The counting decisions

  • Characteristics: counting by IP alone punishes NATed offices and mobile carriers (many users, one IP). Consider JA3/JA4 fingerprints or header-based keys (API keys) for APIs.
  • Cached assets: by default you can choose whether cached responses count toward the rate. For origin protection, count only requests that reach the origin; for abuse prevention, count everything.
  • Counting expression: can differ from the rule expression and can include response fields, so you can count e.g. only failed logins (response 401) toward a brute-force limit. This is the single most useful advanced feature: rate-limit the failure, not the endpoint.

The failure modes

  • Threshold too low on a login endpoint: real users get blocked during normal retry behavior. Log first.
  • Lowering a threshold: add the new rule alongside the old one, wait out the old rule's action duration, then delete the old. Raising a threshold: edit in place.
  • Forgetting that rate limits are per-datacenter characteristics plus key - test from realistic client distributions, not one laptop.

Checklist

  • Log, analyze, then enforce.
  • Count failures (4xx/5xx via counting expression), not raw hits, for auth endpoints.
  • Document the threshold rationale next to the rule; future you will not remember why 100/min.

When to use

You hit exactly this: Cloudflare rate limiting: start in Log mode, count on the right key in Cloudflare rate limiting.

When not to use

A different error, or the same symptom in a different tool. This page only covers the failure above.

Compatibility

Cloudflare rate limiting.

Evidence

Verified against the live rate limiting docs: Log-first recommendation, characteristics (ip.src, JA3, colo), cached-assets counting option, counting expression with response fields, request-rate analysis tab. Ref: https://developers.cloudflare.com/waf/rate-limiting-rules/create-zone-dashboard/

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_feH2ZOKjOh-uImItTpNDbQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Cloudflare rate limiting: start in Log mode, count on the right key <span>— Vectle</span></a>