17 November 2026 · 10 min read · BlitzHash · Cloud, DevOps & Security
Cloudflare WAF rules for an AI-built app: what we blocked and what got through
Short answer: the right Cloudflare WAF rules for an AI-built app are a handful of simple custom rules that block requests for secret files, CMS probes and path tricks, one rate limiting rule on your login, and the free managed ruleset switched on. They cut a lot of attack noise. They don't fix the holes in your code. On Nov 17, 2026 we ran 11 common probe requests and a 51-attempt password burst against a small demo shop built two ways. Our five rules stopped or challenged 7 of the 9 attack requests. Two attacks walked straight past them, and the naive build leaked data on both. If you want someone to run this kind of test against your own app before customers arrive, that's part of our Launch-Ready Check. For a quick first look on your own, try the free self-check.
This guide is for founders who built with Lovable, Bolt, Cursor, Replit or v0 and just put their app on a real domain. You don't need to be an engineer. You need to know what a firewall at the edge can and can't do, and which five rules are worth ten minutes of your time.
What a WAF is, in plain English
A web application firewall (WAF) sits between the internet and your app. Every request passes through it first. If a request matches a rule, the WAF can block it, show a challenge page, or let it through. Cloudflare's WAF only sees traffic for DNS records that are proxied (the orange cloud in the dashboard). A DNS-only record sends visitors straight to your server, and no rule ever runs. Cloudflare's own proxy status docs explain the difference.
Automated scanners request files like /.env, /.git/config and /wp-login.php from sites all over the internet. They aren't aimed at you, but if one of those files is actually reachable, it ends up in someone's list.
Cloudflare gives every plan, including Free, three tools that matter here:
- Custom rules: your own "if the request looks like this, do that" rules. The Free plan allows 5 (custom rules docs).
- Rate limiting rules: "if one visitor sends more than N requests to this path in a time window, block them for a while". The Free plan allows 1 rule, matched on the URL path, with a 10-second counting window and a 10-second block (rate limiting docs).
- The Cloudflare Free Managed Ruleset: rules Cloudflare writes and updates for "high-impact and widely exploited vulnerabilities" (managed rules docs). Paid plans get the broader Cloudflare Managed Ruleset.
Our test: one demo shop, built two ways
We wrote a tiny shop API, the kind an AI tool might produce when you ask for "a product search, a login and a static site". It has a product table with one unreleased product, a users table, a search page, a login endpoint and static file serving. We planted fake "canary" secrets in a .env file and a .git/config file so we could see if they ever came back in a response.
- Naive build: serves static files from the project folder, builds the product search query by gluing the visitor's text into SQL, prints the search term back into the page as-is, and has no login limit. These are common mistakes in both hand-written and AI-written code.
- Hardened build: serves files only from a
publicfolder, uses a parameterized query, escapes the search term before showing it, and locks an account for a while after 5 wrong passwords.
We then replayed 11 requests: 9 attacks (two secret files, two CMS probes, a path traversal, SQL injection with and without a scanner's user agent, a cross-site scripting attempt and an /admin probe) and 2 normal visits. We sent each request to both builds directly, the way an attacker would if they found your server's real IP. In parallel, we ran each request through a small script that mirrors the logic of five Cloudflare custom rules and one Free-plan rate limiting rule. That script is our approximation of the rule logic, not Cloudflare's engine. We couldn't simulate Cloudflare's managed rules offline, so they aren't part of the result.
Cloudflare WAF rules for an AI-built app: the five we tested
All five use only plain operators and functions. That matters, because regular-expression matching (matches) needs a Business or Enterprise plan (operators docs).
Rule 1: block path traversal (action: Block)
(raw.http.request.uri contains "..") or (lower(raw.http.request.uri) contains "%2e%2e")Cloudflare normalizes incoming URLs by default, which includes removing dot segments (URL normalization docs). The raw. field keeps the URL exactly as the visitor sent it, so tricks like ..%2f stay visible to the rule.
Rule 2: block requests for hidden files (action: Block)
(http.request.uri.path contains "/.") and not starts_with(http.request.uri.path, "/.well-known/")This stops /.env, /.git/config, /.aws/credentials and similar. The /.well-known/ exception keeps things like SSL certificate checks and app links working.
Rule 3: block CMS and PHP probes if you don't run them (action: Block)
(http.request.uri.path contains "/wp-") or (lower(http.request.uri.path) contains "phpmyadmin") or ends_with(http.request.uri.path, ".php")Only use this if your app isn't WordPress or PHP. A Next.js, Vite or Lovable app has no reason to answer these.
Rule 4: challenge obvious scanner tools (action: Managed Challenge)
(lower(http.user_agent) contains "sqlmap") or (lower(http.user_agent) contains "nikto") or (lower(http.user_agent) contains "nuclei")Anyone can change their user agent, so this only catches lazy scans. It's still worth a rule because lazy scans are common.
Rule 5: challenge your admin area (action: Managed Challenge)
starts_with(http.request.uri.path, "/admin")Change the path to wherever your admin pages live. A challenge adds friction for bots. It doesn't replace a real login and role check in your app.
The one rate limiting rule: your login
Match the path of your login endpoint (for us, /api/login), count requests per IP, and block above 5 requests in 10 seconds. On Free, the window and the block are both 10 seconds.
What happened: the results
| Request | Our edge rules | Naive build (direct) | Hardened build (direct) |
|---|---|---|---|
GET /.env | Blocked (rule 2) | 200, fake secrets returned | 404 |
GET /.git/config | Blocked (rule 2) | 200, fake token returned | 404 |
GET /wp-login.php | Blocked (rule 3) | 404 | 404 |
GET /phpmyadmin/index.php | Blocked (rule 3) | 404 | 404 |
Path traversal to /etc/passwd | Blocked (rule 1) | 200, system file returned | 404 |
SQL injection ' OR 1=1 -- in search | Passed | 200, unreleased product returned | 200, no match |
| Same SQL injection, sqlmap user agent | Challenged (rule 4) | 200, unreleased product returned | 200, no match |
| Script tag in search (XSS) | Passed | 200, script reflected into page | 200, escaped |
GET /admin | Challenged (rule 5) | 404 | 404 |
| Normal home page and search | Passed | 200 | 200 |
Four things stood out.
1. The rules cleaned up most of the noise. 7 of the 9 attack requests were blocked or challenged before they would have reached the app. Both normal visits passed. In a real log, that's the difference between scrolling through hundreds of /wp-login.php lines and seeing the few requests that matter.
2. The two attacks that cost money got through. Our five custom rules didn't stop the plain SQL injection or the script injection, because they look like ordinary search text. On the naive build, the injection returned a product that wasn't supposed to be public yet, and the script came back inside the page. Cloudflare's managed rules are designed for this kind of request, but we couldn't test them offline, and no ruleset catches every variation. The fix that worked every time was in the code: a parameterized query and escaped output. The hardened build was safe even with no WAF in front of it.
3. The rate limit stopped the burst, not the attacker. In our 51-attempt login burst (50 wrong passwords, then the right one), the edge rule would have blocked 46 attempts. But a patient attacker who sends 5 guesses every 10 seconds never trips it. That's up to 43,200 guesses a day from one IP, just under the limit. Sent straight to the naive build, the correct password was accepted after 50 failures. The hardened build answered with a lockout instead, because the protection lived in the app.
4. None of it helps if the server's real address is public. Every "direct" column above is what an attacker gets when they skip Cloudflare. If your origin answers anyone on the internet, the WAF is a front door with no walls. Lock the origin so it only accepts traffic from Cloudflare.
What an exploit attempt looks like in your logs
Here's what the naive build's own log recorded. These are real lines from our test, trimmed:
GET /.env -> 200 SECRET-OR-SYSTEM-FILE-SERVED
GET /.git/config -> 200 SECRET-OR-SYSTEM-FILE-SERVED
GET /wp-login.php -> 404 not-found
GET /..%2f/..%2f/..%2f ... etc%2fpasswd -> 200 SECRET-OR-SYSTEM-FILE-SERVED
GET /api/products?search=%27%20OR%201%3D1%20-- -> 200 rows=3
GET /api/products?search=mug -> 200 rows=1
GET /search?q=%3Cscript%3Efetch(... -> 200 REFLECTED-SCRIPTA few patterns to learn to spot, in Cloudflare's Security Events or your host's logs:
- Dotfile requests (
/.env,/.git/): any 200 response here is an emergency. Rotate every key in that file today. - Encoded quotes and keywords (
%27,OR 1=1,UNION,--) in query strings: someone is testing your database queries. - Encoded angle brackets (
%3Cscript) in search or form fields: someone is testing whether your pages echo input back. - A "normal" search that returns far more rows than usual (our
rows=3versusrows=1): the response size often tells you more than the request. - Bursts of 401s on the login path, especially from many IPs against one email: credential guessing.
The 10-minute setup checklist
1. In Cloudflare DNS, confirm the records that serve your app are Proxied, not DNS-only. 2. Turn on the Free Managed Ruleset (or the Cloudflare Managed Ruleset on a paid plan). 3. Add the five custom rules above, in that order. Remove rule 3 if you run WordPress or PHP. 4. Add one rate limiting rule on your login path. 5. Lock your origin so it only accepts requests from Cloudflare (or uses a tunnel). Then try to load your server's IP directly. It should fail. 6. If you're on Vercel, read Vercel's guide on using Cloudflare with Vercel first. Vercel recommends connecting directly where possible because it has its own CDN and firewall, so you may want its firewall rules instead of a second proxy. 7. Watch Security Events for a week. If a real customer gets blocked, use the event to see which rule fired and adjust it.
The test steps to run on your own app
These are safe to run against an app you own. Don't run them against anyone else's.
1. Open https://yourdomain.com/.env and https://yourdomain.com/.git/config in a private window. Anything other than a block page or a 404 is a problem. 2. Search your app for ' (a single quote). An error page that mentions SQL, or a strange result, needs a developer's attention. 3. Search for test. If the word shows up bold, your page is printing input as HTML. 4. Try 10 wrong passwords on your own test account. If nothing slows you down or locks you out, the login has no protection of its own. 5. Find your server's real IP (your host's dashboard shows it) and open it in a browser. If your app loads, attackers can skip your WAF.
If any step fails, our earlier guides go deeper: the plain-English OWASP audit checklist for code-level fixes, and the Cloudflare Turnstile signup test for bot signups. Our open-source Cloudflare production skills repo has setup notes you can hand to an AI coding tool.
FAQ
Is Cloudflare's free plan enough for a new AI-built app?
For most early apps, the Free plan's WAF features (5 custom rules, 1 rate limiting rule, the Free Managed Ruleset) are a reasonable start. The bigger limits are the 10-second rate window and no regex matching. They matter less than fixing the code underneath.
Will these rules block real customers?
They shouldn't, because real visitors don't ask for /.env or /wp-login.php. The two to watch are the /admin challenge (your own team will see it) and the login rate limit if many people share one office IP. Check Security Events in the first week.
Does a WAF stop SQL injection?
Sometimes. Managed rules catch many common patterns, but our test showed that simple custom rules don't, and attackers vary their payloads. The dependable fix is parameterized queries in your code. Treat the WAF as a seat belt, not the brakes.
My app is on Lovable or Vercel. Can I still use Cloudflare's WAF?
Only if your domain's traffic is proxied through Cloudflare, and your host has to support that setup. Check your host's guidance first. Vercel, for example, has its own firewall and publishes advice about putting another proxy in front.
Want a second pair of eyes?
A WAF buys you time. It doesn't tell you whether your secret files, queries and login are safe. Our Launch-Ready Check runs these tests and more against your app and gives you a written report on what to fix first. Not sure yet? Start with the free self-check, or book a free technical assessment and we'll look at your setup with you.
Sources
- Cloudflare Docs: Custom rules (availability and rule limits by plan)
- Cloudflare Docs: Rate limiting rules (Free plan fields, 10 s period and timeout)
- Cloudflare Docs: Managed Rules and the Free Managed Ruleset
- Cloudflare Docs: Rules language operators (matches requires Business or Enterprise)
- Cloudflare Docs: Rules language functions (starts_with, ends_with, lower)
- Cloudflare Docs: How URL normalization works
- Cloudflare Docs: Proxy status (proxied vs DNS-only)
- Vercel Knowledge Base: Using Cloudflare with Vercel
