Rate Limiting
Exact per-visitor counters at the edge: a site-wide limit, per-endpoint limits, per-country overrides, burst allowance, progressive response and a deny list.
Why per-request counts
Most attacks aren't one big request — they're hundreds or thousands. Brute-forcing a login, scraping a product catalog, enumerating user IDs all generate spike patterns that look nothing like a real user's. Rate limiting catches them by counting requests per identity and blocking when the count exceeds a budget.
Identity keys
A site counts requests by one identity, set under Rate Limit Key:
- IP address — the default. Effective against single-source attacks.
- API key header — the value of a header such as
X-API-Key. - Session cookie — the value of a cookie, so one user is one budget across IPs.
- Custom header — any header you name, e.g.
X-Tenant-IDfor a multi-tenant SaaS.
When the header or cookie is missing from a request, that request is counted by its IP. Header and cookie names are validated when you save; a name a browser could not send is rejected.
A client chooses its own header values. A custom header only makes a good key when your own gateway sets it, not the browser: otherwise a client can send a new value with every request and get a fresh budget each time.
Limits
- Site-wide limit — requests per window for every identity.
- Endpoint limits — a path (exact, or a prefix ending in a path segment) and optional method with its own budget, counted separately from the site-wide one.
- Country overrides — a different budget for visitors from a given country.
- Burst allowance — extra requests per 5 seconds once a window is used up.
- Authenticated multiplier — a larger budget for requests carrying a bearer token, a session cookie or an auth header (a convenience, not authentication).
How counting works
Counters live in a Cloudflare Durable Object per site and identity, created near the visitor. Each request is one round trip that counts and decides together, so concurrent requests are counted exactly. Windows are fixed and aligned to the clock: a 60-second window resets on the minute. A request over the limit is not counted. If the limiter cannot answer in time, the site's fail mode applies.
Actions
- Block — 429 Too Many Requests with
Retry-AfterandX-RateLimit-*headers, so well-behaved clients back off until the window resets. - Progressive response — the first violation is let through after a short delay, the second gets a challenge, the third and later are blocked. The count resets after 10 minutes without a violation.
- Block + deny list — once a request is blocked, every further request from the same identity (the IP, or the session the site counts by) is denied for the number of minutes you set (up to a day), not just until the window resets. A challenge the visitor can solve does not trigger it, nor does a request an exception rule lets through. Turning the option off lifts every entry at once. Not available when counting by an API key or a custom header: a client chooses those values (many API keys are public), so it could put someone else's on the deny list.
- Monitor mode — a site in monitor mode records what rate limiting would block without blocking it. Use it to set budgets before enforcing.
Exemptions
- Whitelisted IPs — never rate limited (site-wide).
- ASNs — requests from these networks are never rate limited, site-wide or for one endpoint limit.
- User-Agent contains — requests whose User-Agent contains one of these strings (case-insensitive, at least 4 characters), site-wide or for one endpoint limit. A User-Agent is easy to fake: use it for your own monitors and partner integrations, never as a security boundary.
- Blocked IPs — always blocked, whatever the counts.
A Shield exception rule that names rate_limit can also exempt specific requests.
Common setups
# Login brute-force protection
key: IP
endpoint: POST /login — 5 requests / 300 seconds
block + deny list: 15 minutes
# API per-key fair use
key: API key header (X-API-Key)
site-wide: 1000 requests / 60 seconds
exempt ASN: your own monitoring network
# Per-tenant budget on a multi-tenant SaaS
key: custom header (X-Tenant-ID)
endpoint: /api/v1/reports — 10 requests / 3600 secondsTuning
Start with the site in monitor mode and generous budgets, watch what would be blocked, then tighten. Budgets about twice what your busiest real users send usually stop abusers without catching people.
What's next
- IP Access — allow and deny lists for whole networks and countries.
- Managed Rulesets — credential-stuffing patterns that complement rate limiting.