WordPress Security ServicesMalware Removal
Hardening

Cloudflare Firewall Rules for WordPress: 5 Rules That Work on the Free Plan

If your WordPress site runs behind Cloudflare, you can stop a lot of attacks before they ever reach your server, even on the free plan. Here are five custom firewall rules I'd put on almost every WordPress site, with the exact expressions, plus a rate-limiting rule for the login page.

Sergey By Sergey, WordPress security specialist Updated 2 min read
In this guide
  1. Before you start
  2. Rule 1: Challenge access to the login and admin area
  3. Rule 2: Block xmlrpc.php
  4. Rule 3: Block PHP in uploads
  5. Rule 4: Block access to sensitive files
  6. Rule 5: Your choice
  7. Rate-limit login attempts
  8. Also turn on

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.

Sergey, WordPress Security Specialist
About the author
Sergey, WordPress Security Specialist

10 years in WordPress security and incident investigation, and more than 200 websites cleaned of malware. Top Rated on Upwork with a 100% Job Success score. More about me

Frequently Asked Questions

Does the free Cloudflare plan include a WAF?

Yes, in a limited form. At the time of writing, the free plan includes Cloudflare's Free Managed Ruleset, 5 custom rules and 1 rate limiting rule. The full Cloudflare Managed Ruleset and the OWASP ruleset need a paid plan.

Can Cloudflare replace my WordPress security plugin?

Not completely. Cloudflare filters traffic before it reaches your server; a security plugin protects inside WordPress and scans files. They work well together. Cloudflare handles the noise, the plugin handles what gets through.

Can attackers bypass Cloudflare?

Yes, if they know your server's real IP address, they can connect to it directly. Ask your host to only accept web traffic from Cloudflare's IP ranges, and avoid exposing the origin IP, for example through old DNS records.

Will these rules lock me out?

The wp-admin and login rule uses a challenge, not a block, so you can still log in after passing it. Test each rule after adding it, and keep one browser session logged in while you do.

Need a hand?

Let me clean your WordPress site for you

Send me your site URL and what you're seeing. I'll reply with what I think is going on and the next step.

$95 per infected site · 1-month guarantee · direct contact with the specialist

Get My Site Cleaned →