Rate limiting rules: slow down anyone who hammers one address
Rate limiting rules (WAF rate limiting by IP, period, and duration)
What it is
A rate limiting rule counts how many requests one visitor sends to the addresses you choose, and acts once they go over a limit you set. It sits in each zone under Security, alongside the custom WAF rules from lesson 15, and you create it with Create rule, then Rate limiting rules.
Every rule has five parts: a filter (which requests count, for example hostname equals one subdomain), the characteristic that identifies a visitor (on the Free plan this is fixed to their IP address), the rate (a number of requests per period), the action when the rate is exceeded, and the duration that action lasts.
On the Free plan you get one rate limiting rule per zone, the period is 10 seconds, the action is Block, and the block lasts 10 seconds. A blocked visitor sees an error page with status 429, which means too many requests. Paid plans add more rules, longer windows, and a challenge instead of a hard block.
Why it matters
Your small apps have endpoints that cost something when abused: a contact or referral form that sends email, a Worker that calls Workers AI (lesson 14), or a login page. A bot hitting one of those thousands of times can burn your free quota or fill an inbox. A rate limit caps that without any code.
It works alongside Turnstile (lesson 21). Turnstile checks that a single submission comes from a person, while a rate limit stops one address from submitting over and over. Together they cover most form abuse on a hobby or clinic app.
Because the Free plan gives only one rule per zone, spend it on the one path that matters most, such as a form endpoint, rather than the whole domain. Set the limit well above what a real person would ever do, so normal visitors never notice it.
On your account
From your own setup: this tutor lives at cloudflare.kosan.xyz on your kosan.xyz zone. A rule with the filter Hostname equals cloudflare.kosan.xyz, counting by IP, 20 requests per 10 seconds, action Block for 10 seconds, would leave normal reading untouched but block a script that grabs pages in a tight loop.
You can trigger it yourself from a terminal with a short loop: for i in $(seq 1 30); do curl -s -o /dev/null -w "%{http_code} " https://cloudflare.kosan.xyz/; done. The first answers print 200, and once you pass the limit they switch to 429. Counting is spread across Cloudflare's data centres, so a few extra requests can slip through before the block starts. Ten seconds later the pages load normally again.
Nothing was run for this lesson. This desk only redeployed its own Worker, cloudflare-tutor, and did not create any rule, change DNS, or touch the AI News root redirect rule, ainews, aiweekly, or any other Worker.
Do this yourself
These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.
- On the kosan.xyz zone, check that no rate limiting rule already exists (the Free plan allows one), then create one that matches only Hostname equals cloudflare.kosan.xyz, counts by IP, allows 20 requests per 10 seconds, and blocks for 10 seconds; run the 30-request curl loop from the example to watch 200 turn into 429, look for the block under Security Events, then delete the rule.