In this guide
Before you start
- Your site’s DNS records must be proxied (orange cloud) in Cloudflare. Otherwise traffic skips the firewall.
- Rules are created under Security → WAF → Custom rules. You can use the visual builder, or paste the expressions below with Edit expression.
- The free plan allows a limited number of custom rules (5 at the time of writing). The five below fit that limit.
Rule 1: Challenge access to the login and admin area
Bots constantly hit wp-login.php and wp-admin. A Managed Challenge stops most of them while real users pass with a click or automatically.
(http.request.uri.path eq "/wp-login.php") or (http.request.uri.path contains "/wp-admin/" and not http.request.uri.path contains "/wp-admin/admin-ajax.php")
Action: Managed Challenge. admin-ajax.php is excluded because many plugins use it for visitors on the front end.
Rule 2: Block xmlrpc.php
If you don’t use Jetpack or a remote publishing app (see XML-RPC):
(http.request.uri.path eq "/xmlrpc.php")
Action: Block.
Rule 3: Block PHP in uploads
There’s no legitimate reason for visitors to run PHP files from the uploads folder, and it’s where backdoors hide:
(http.request.uri.path contains "/wp-content/uploads/" and http.request.uri.path contains ".php")
Action: Block.
Rule 4: Block access to sensitive files
(http.request.uri.path contains "wp-config") or (http.request.uri.path contains "/.git") or (http.request.uri.path contains "/.env") or (http.request.uri.path contains ".sql")
Action: Block. Adjust it if you genuinely serve a file matching these patterns.
Rule 5: Your choice
Use the last slot for what fits your site, for example:
- challenge traffic from countries you never do business with (use the Country field in the builder);
- block known-bad user agents you see in your logs;
- block
?author=scans, which reveal usernames (see user enumeration).
Rate-limit login attempts
Under Security → WAF → Rate limiting rules, create a rule for requests where the path equals /wp-login.php and the method is POST, with a low threshold, and a block or challenge action. The free plan’s options are limited (one rule, short counting period), but it still slows down password-guessing bots.
Also turn on
- Always Use HTTPS (SSL/TLS → Edge Certificates).
- Bot Fight Mode (Security → Bots), then check that it doesn’t block services you rely on, such as payment webhooks.
- The Free Managed Ruleset, which is enabled by default on the free plan. Leave it on.
From my cleanup work: Cloudflare doesn’t clean an infected site. If malware is already on the server, it keeps working. But on sites I’ve cleaned, these rules make the next attack much harder and cut the bot traffic in the logs dramatically, which makes anything suspicious much easier to spot.
Cloudflare’s dashboard and plan limits change from time to time. Field names and limits are as of November 2026; check Cloudflare’s WAF documentation if something looks different.