Your site is public. People read it, and so do search engines and AI assistants, along with scrapers, scanners of well-known paths, and SQL injection probes. You're on Cloudflare's Free plan: 5 custom rules and 1 rate-limiting rule. The practical question is not "how do I configure the WAF," but which of those six slots you use for each problem, and how you find out when you got it wrong.
This is what I did on Elección Clara, a site about candidates, parties, and government in Peru: SvelteKit 2 with Svelte 5 on a Cloudflare Worker, and a Go API with PostgreSQL behind it. I'll cover the policy, how I split the rules, three things that went wrong, and the checklist I was left with.
I don't publish rule expressions, thresholds, identifiers, or lists of paths or User-Agents, and this is not a guide to bypassing anything. When I show an expression, it is a generic example from Cloudflare's documentation, and I mark it as such. The figures come from Security Events on the Free plan, which are sampled, so they are rounded and are orders of magnitude, not totals.
The order in which Cloudflare evaluates your traffic
Before you split rules, it helps to know the order they run in, because a terminating action stops evaluation. According to the security features interoperability documentation, the relevant order for a site like this is: custom rules, then rate limiting, then managed rules. Bot Fight Mode sits outside that, cannot be skipped with a rule, and cannot be customized.
request ──▶ [Cloudflare edge] 1. custom rules (5) ← categories of unwanted traffic 2. rate-limiting rule (1) ← bursts Bot Fight Mode / AI crawler protection ──▶ [SvelteKit Worker] 3. local filter in hooks.server.ts (403 before rendering) ──▶ [Go API] 4. parameterized queries with pgx What the edge stops never reaches the Worker. That sounds obvious, but it has a consequence: if your report comes from the Worker logs, the requests the WAF already cut never show up there. That happened to me with my first report. To see what was blocked, you have to look at Cloudflare's Security Events.
What I allow and what I block
Policy first, then the rules. In one sentence: I let through what Cloudflare verifies as a search engine, or as an assistant that reads at a person's request, and I block anyone who announces itself as a training crawler, an SEO tool, or a generic scraper.
| Category | Decision | Why |
|---|---|---|
| Verified search engine crawlers | Allow | The site is public and I want it to be found |
| Verified link previewers | Allow | They build the card when someone shares a URL |
| Verified AI Search and AI assistants | Allow | They answer a person who asked something, and they may cite you |
| AI crawlers for training | Block | They send no traffic back and they request the most pages |
| SEO tools and generic scrapers | Block | They request a lot of pages and give the site nothing |
| Hosting networks that are not a verified bot | Block | A normal visitor does not browse from a datacenter |
"Verified" is a Cloudflare concept, not mine: it is expressed by the cf.verified_bot_category field, with values such as Search Engine Crawler, Page Preview, AI Search, AI Assistant, AI Crawler, or Search Engine Optimization. The difference from looking at the User-Agent is large: the User-Agent is written by whoever makes the request, and the verified category is assigned by Cloudflare. A bot that claims to be Googlebot without being one does not get in that way.
That policy also has a burst limit: in the read sections, where anyone can chain many pages in a row, the same client cannot request hundreds per minute. The exceptions: verified search engines and assistants, and the route SvelteKit uses to fetch its own page data, which a real visitor triggers several times without meaning to.
How I split 5 rules and 1 rate limit
The Free plan has 5 custom rules, it accepts every action except Log, and it does not allow regular expressions. That forces you to group by category, not by incident. This is how the split looked at the end of November 2026:
| Slot | What it covers (in concepts) | Action | Exception |
|---|---|---|---|
| Rule 1 | SQL injection signatures in the URL | Block | None |
| Rule 2 | Probes for files that should not exist on a public site: hidden files, secrets, backups, configuration, build artifacts, and directory traversal | Block | None |
| Rule 3 | Probes for well-known admin panels and APIs from other platforms (CMS products, server-side languages, admin consoles) | Block | None |
| Rule 4 | Clients that announce themselves as scrapers, or with a spoofed User-Agent | Block | Verified categories I allow |
| Rule 5 | Traffic from hosting networks | Block | Verified categories I allow |
| Rate limit | Bursts in the read sections | Block | Verified bots and SvelteKit's data route |
Three decisions behind that table:
- I grouped the probes into two rules, not one per system. Every slot costs. One rule for file probes and another for well-known admin panels cover a lot of ground without spending all five.
- I edited rules instead of adding new ones. When I needed to cover a SQL injection variant, I rewrote rule 1 in place. And on Free the rate-limiting rule is constrained too: its expression can only look at the path and whether the client is a verified bot, it counts by IP, and the period is 10 seconds, according to the availability table.
- Exceptions go by verified category, never by User-Agent. Anyone can copy a User-Agent exception.
A generic example from Cloudflare's documentation (it is not one of my rules, and the Bot Management fields it uses require an Enterprise plan) is enough to see the shape of a rule that challenges bots without touching verified ones:
# Generic example, taken from Cloudflare's documentation ("Challenge bad bots"). # It does not correspond to any of my rules. (cf.bot_management.score gt 1 and cf.bot_management.score lt 30) → action: Managed Challenge Source: Challenge bad bots. On Free, the verified category is used as an exception inside the expression, not as a score.
Managed Challenge or Block
Cloudflare recommends Managed Challenge for most WAF rules: if the client is a person, they solve it and continue; if it is a bot, they stay there. On Free there is no log-only mode, so a challenge is the closest thing to testing a rule in production without cutting anyone off at once.
I applied that to the hosting-networks rule. I put it on Managed Challenge, and after about 24 hours I looked at the result: on the first day there were on the order of 3,000 challenges, from about 2,000 distinct IPs, and only one of them solved it. That morning, until I changed it, none did either. Nobody was solving it, so I switched it to Block on November 22, around 11 a.m. (Lima time, America/Lima).
The kind of rule that can block without going through a challenge is the one that covers things no person asks for: SQL injection, secret files, admin panels from other platforms. A challenge adds nothing there, because there is no human who would solve it.
There is a limitation that constrains where you can use a challenge: according to the challenge pages documentation, challenge pages fail on AJAX or fetch requests, because the browser cannot render them inside a data response. In SvelteKit, client-side navigation fetches page data with fetch, so a challenge on that route can break a navigation that looked valid. In my case the rate limit blocks (it does not challenge) and excludes that data route.
A challenge also deserves a pass for false positives. With that rule I saw a verified AI assistant get hit, nine requests, and on November 22 I added the exception by verified category.
The Worker as a second layer
The Worker filter lives in hooks.server.ts, it runs before rendering, and it responds 403. It is a second list that mirrors the edge policy. It does two things: it cuts the request without spending a render if something gets through, and it feeds robots.txt with the same policy, so what I say and what I do stay in sync.
The generic version of the idea, which I did run (the patterns are examples):
type CfRequest = Request & { cf?: { verifiedBotCategory?: string } }; const ALLOWED = new Set(['Search Engine Crawler', 'Page Preview', 'AI Search', 'AI Assistant']); const BLOCKED = [/example-scraper/i, /example-seo-bot/i]; // your list export function shouldBlock(request: CfRequest): boolean { const category = request.cf?.verifiedBotCategory; if (category && ALLOWED.has(category)) return false; // Cloudflare verifies this const ua = request.headers.get('user-agent') ?? ''; return BLOCKED.some((re) => re.test(ua)); } // shouldBlock('example-scraper/1.0') → true // … with verifiedBotCategory 'Search Engine Crawler' → false // … with verifiedBotCategory 'AI Crawler' → true Watch out for three things:
- The
request.cf.verifiedBotCategoryproperty does not appear in therequest.cfdocumentation, which only describesbotManagement.verifiedBot(with Bot Management). I read it defensively, and if it is missing, the filter is left with only the User-Agent. Check it with a log in your Worker before you rely on it. - A User-Agent list only stops whoever announces themselves; someone who disguises themselves as a browser gets in. What the verified category adds is the ability to let search engines through without trusting what the User-Agent says.
- It is a copy of the edge policy: if you change one and forget the other, they drift apart.
Reading Security Events to adjust the rules
On Free, Security Events show only sampled records, with 31 days of retention, and an event is not the same thing as a request. That is what I work with: an automatic daily report that reads the events and tells me which rule blocked what, with approximate figures. Four lessons came out of that reading, and several of them are mistakes of mine.
1. The rate limit was hitting real people. When I tightened it, the report showed blocks of real Peruvian users: in one day, on the order of 136 blocks hitting about ten people, versus about 49 hitting three scrapers. Because on Free you only count by IP, a shared IP pays for everyone behind it.
2. A bot-management toggle blocked verified search engines. I switched the setting for AI training crawlers from "do not allow" to "block." The next day's report showed on the order of 2,500 blocks on that first day alone, aimed at search engine crawlers I wanted to let through. I corrected it on November 26, three days after the alert. If you want to avoid that, review blocks by verified category the day after you touch any bot toggle.
3. "Verified" does not mean harmless. A verified AI crawler, which came in through my own category exception, made on the order of 60,000 requests in three hours and caused 5xx errors on the Worker. The verified bots policy says a verified bot must maintain reasonable request rates, and that Cloudflare can revoke the status if it does not. In the meantime, the exception is a decision of mine with a cost, not a guarantee.
4. Blocking hosting networks also cuts off robots.txt and the sitemap. Any client from those networks, good or bad, gets the same block. That is a cost of the block worth knowing: someone who cannot read robots.txt cannot obey it either.
The AI Labyrinth, the crawler protection that injects invisible links, gave me another signal: according to the documentation, those events are not mitigations, only signals. In one day the labyrinth marked thousands of residential IPs with one or two requests each. That is information from which no automatic block follows.
A case: SQL probes from residential IPs
In mid-November 2026, automated SQL injection probes arrived against public pages. They did not come from a datacenter: they were residential IPs in France and Spain.
- On November 14, at 14:01 (Lima time), a burst of about 44 seconds made about 85 requests. The SQL rule did not exist yet: I created it on November 16 at 00:33. They received 404s; no data came out.
- On the 15th, between 11:42 and 11:43, there was another. The edge rate limit stopped at least 20 of that burst (a count over the last visible events, so there may have been more).
- The Worker logs grouped, over seven days, 120 attempts on three residential IPs.
- On November 21, the custom rule stopped 666 probes of the same kind, again from a residential ISP in Spain.
The first version of the rule had a gap I found by testing it against the attacks already on record: it did not normalize URL encoding before inspecting the URL, and the encoded variants slipped through. It detected 81% of the known attacks. I rewrote it to normalize the URL and to look for specific SQL signatures, never loose words such as "select." Before I turned it on I tested it against 99,090 distinct legitimate requests from the previous seven days, including free-text searches, apostrophes, parentheses, and the name of a party that contains "Unión." It blocked 0, and it detected 824 of 824 recorded attacks. That is about the attacks I had already seen, not a guarantee against the ones I have not.
This is why blocking by IP or by ASN does not work with residential traffic: a home IP changes, and real visitors use the same ISP. A scraper I had blocked in another episode later reappeared, probably from a different IP (that is an inference from the report, not a certainty). With hosting networks the block works because almost nobody legitimate browses from there. With residential traffic, the defense has to look at what is being requested, not where it comes from.
And the WAF is not the last layer. At the origin, the Go API uses parameterized queries with pgx: the user value travels as an argument and is never concatenated into the SQL. This example was compiled with pgx 5.13.0 (go vet):
rows, err := pool.Query(ctx, `SELECT id, name FROM people WHERE name ILIKE $1 ESCAPE '\' LIMIT 20`, "%"+escapeLike(q)+"%") escapeLike neutralizes %, _, and \ so the user's text does not act as a wildcard; the SQL fragments are fixed and the values always go as arguments. If the WAF fails, or you remove it tomorrow, this layer is still there.
Turnstile, in one paragraph
I use Turnstile only on the suggestion box, which is the site's only public write: the browser obtains a token, and the Worker validates it against the Siteverify API before forwarding anything to the Go API. I added it on November 1, 2026, as a preventive measure, because that inbox had no observed spam. It plays no part in any of the above: the WAF covers reads and bursts, Turnstile covers a form, and neither replaces authorization or server-side validation. If you use it, the widget alone protects nothing: you have to call Siteverify from the server.
Honest limits
- Rules that key off the IP fall down on residential and shared IPs. Free counts only by IP, and the counters are per data center, according to the request rate calculation documentation.
- Bot Fight Mode cannot be skipped or tuned. If it stops someone, the only switch is to turn it off.
- Managed Challenge does not work on data routes (
fetch/AJAX). - Security Events on Free are samples. The figures in this piece are approximate.
- Exceptions for verified bots are a decision with a cost. Verified is not the same as well-behaved.
- The WAF is not the last layer. An edge rule does not replace validating on the server or parameterizing queries.
- Turnstile is not authorization or a rate limit, and it does not protect reads.
Checklist
- Does your policy say which verified categories you allow and which you block, before you write any rule?
- Do exceptions go by verified category, not by User-Agent?
- Did you test each new rule against your legitimate traffic from the last few days?
- Do you start with Managed Challenge where a human might be caught, and move to Block when nobody solves it?
- Did you exclude from the challenge and from the rate limit the data routes your framework fetches with
fetch? - Do you review Security Events the day after you touch any bot toggle?
- Do you have parameterized queries at the origin, in case the WAF fails?
- Do your Worker and your edge apply the same policy?
References
- Cloudflare, WAF custom rules
- Cloudflare, Rate limiting rules and Request rate calculation
- Cloudflare, Security features interoperability
- Cloudflare, Security Events
- Cloudflare, Challenge pages
- Cloudflare, Workers:
request.cf - Cloudflare, Bot Fight Mode
- Cloudflare, Verified bots: categories and policy
- Cloudflare, AI Labyrinth
- Cloudflare, Challenge bad bots (generic example)
- Cloudflare, Turnstile: validate the token (Siteverify)
- SvelteKit, Hooks
The Worker filter was run with Node.js 24.22.1, and the Go example was compiled with go vet and pgx 5.13.0. In production I use SvelteKit ^2.63.0 and Svelte 5.