Security

WordPress Firewalls (WAF) Explained: Plugin vs Cloud Firewalls, Useful Rules, Rate Limiting and False Positives

WordPress firewall (WAF) explained: plugin firewalls vs Cloudflare and Sucuri, rules worth adding, rate limiting, false positives and which setup suits.

WordPress Firewalls (WAF) Explained: Plugin vs Cloud Firewalls, Useful Rules, Rate Limiting and False Positives
On this page
  1. What a firewall does, and what it can't
  2. Plugin, server and DNS-level firewalls compared
  3. Rules worth having on a WordPress site
  4. Rate limiting
  5. False positives: when the firewall blocks the wrong thing
  6. Which setup suits your site
  7. Testing your firewall after setup
  8. Quick check: is a firewall actually protecting you?
  9. When to get help
  10. FAQs
Key takeaways
  • A plugin firewall such as Wordfence runs on your server and understands WordPress, while a DNS-level firewall such as Cloudflare or Sucuri filters traffic before it reaches your hosting.
  • The rules that matter most on WordPress protect the login, XML-RPC, checkout and forms, and rate limiting on those few URLs stops most bot floods without affecting real visitors.
  • Every firewall blocks something legitimate sooner or later, so find the exact rule in the logs and add a narrow exception rather than switching the firewall off.

A web application firewall (WAF) sits between visitors and your WordPress site and blocks requests that look like attacks: exploits for known plugin flaws, password guessing, malicious bots and floods of requests. It can run in three places. A plugin firewall such as Wordfence runs on your server and understands WordPress users; a server firewall such as ModSecurity or Imunify360 is run by your host; and a DNS-level firewall such as Cloudflare or Sucuri filters traffic before it reaches your hosting at all. For most business sites, a cloud or host firewall plus one security plugin for logins is a sensible combination.

A firewall helps keep attackers out, but it won't remove malware that is already inside. Firewall setup is part of the hardening in my WordPress malware removal service, after the site has been cleaned.

What a firewall does, and what it can't

A WAF can usually blockA WAF can't fix
Known exploit attempts against plugins and themesA plugin flaw no rule covers yet
Password guessing on wp-login.php and XML-RPCSomeone logging in with a stolen password and a valid 2FA code
Common attack patterns such as SQL injection and cross-site scriptingMalware and backdoors already on the server
Bad bots, scrapers and request floodsAn admin installing a nulled plugin
Requests from IP ranges or countries you choose to blockWeak hosting security or another infected site in the account

Many firewalls also offer virtual patching: when a new plugin flaw is published, the vendor adds a rule that blocks attempts to exploit it, which protects you in the gap before you update. It is a safety net, not a reason to delay updates.

Plugin, server and DNS-level firewalls compared

TypeExamplesStrengthsWeaknesses
PluginWordfence, NinjaFirewallUnderstands WordPress users and roles; easy to install; works on any hostBlocked requests still reach your server and use its resources
ServerModSecurity, Imunify360, host firewallsNothing for you to manage; protects every site in the accountThe host controls the rules; false positives need a support ticket
DNS-level (cloud)Cloudflare, Sucuri Website FirewallBlocks traffic before it reaches your hosting; adds a CDN and protection from traffic floodsNeeds DNS changes; can be bypassed if attackers find your server's real IP

Plugin firewalls

Wordfence's firewall has two modes. In basic mode it loads with WordPress like any plugin. In extended protection mode it uses a PHP setting to run before WordPress loads, so it can inspect requests to any PHP file and is harder for malicious plugin code to sidestep. It starts in a learning mode for about a week to get used to how your site normally behaves. Plugin firewalls are good at login protection and WordPress-aware rules, but on a busy site under attack, every blocked request still costs your server some work.

Server firewalls

Many hosts run ModSecurity with a rule set, Imunify360 or their own system. You may not know it is there until it blocks something, often with a 403 error when you save a page containing code. Ask your host which firewall they use and how to request an exception.

DNS-level firewalls

With Cloudflare or Sucuri, your domain's DNS points to the provider, visitors connect to them, and only filtered traffic is passed to your server. That keeps floods and bot traffic off your hosting entirely. Two things to get right: the SSL mode, because a wrong setting causes redirect loops (see setting up Cloudflare on WordPress), and the origin, because attackers who discover your server's real IP address can go round the firewall. Ask your host to accept web traffic only from the provider's IP ranges, or use the provider's own origin protection.

At the time of writing, Cloudflare's free plan includes a managed rule set for widely exploited flaws, a few custom rules and basic rate limiting, while its WordPress-specific managed rules come with paid plans. Sucuri's firewall is a paid service. Plans change, so check the current details.

Rules worth having on a WordPress site

  • Managed rule sets turned on, for known exploits and virtual patches
  • Block xmlrpc.php if nothing on your site uses it; Jetpack and some apps do, so check first with WordPress XML-RPC explained
  • Challenge or rate-limit login attempts on wp-login.php and the WooCommerce account login
  • Block direct requests to PHP files in uploads, where only media should be
  • Leave admin-ajax.php and the REST API reachable, because themes, forms and WooCommerce use them on the front end

In Cloudflare's custom rules, the expressions look like this. The first matches XML-RPC, the second matches anyone posting to the login page, and the third matches PHP requests inside uploads:

(http.request.uri.path eq "/xmlrpc.php")
(http.request.uri.path eq "/wp-login.php" and http.request.method eq "POST")
(http.request.uri.path contains "/wp-content/uploads/" and http.request.uri.path contains ".php")

Use Block for the first and third, and Managed Challenge for the second, so real people can still log in. Test each rule after adding it.

Should you block other countries?

If every customer is in India, it is tempting to block the rest of the world. Blocking or challenging other countries on the login page only is a reasonable middle ground, because you and your team are the only people who use it. Blocking whole countries from the entire site is riskier: Googlebot and other crawlers, payment gateway webhooks, uptime monitors and customers travelling or using a VPN can come from anywhere, and attackers can rent servers inside India too. If you do use country rules, exclude known services and check Search Console's crawl stats afterwards.

Rate limiting

Rate limiting caps how many requests one visitor can make to a URL in a set time. Applied to a few sensitive or expensive URLs, it stops bot floods without affecting normal visitors, who rarely send more than a handful of requests to any of these.

URLWhy limit it
/wp-login.php and the WooCommerce my-account loginPassword guessing
/xmlrpc.php, if you can't block itMany password guesses in a single request
Checkout: /?wc-ajax=checkout and /wp-json/wc/store/v1/checkoutCard-testing bots; see the WooCommerce security checklist
Search (?s=) and contact or quote formsSpam and floods that load the database

Start with generous limits and tighten them only if attacks get through. Set them too strict and customers on office or mobile networks, who can share one IP address, get blocked.

A common false positive is the block editor's save request, which shows up as WordPress "Updating failed. The response is not a valid JSON response".

False positives: when the firewall blocks the wrong thing

Every firewall blocks something legitimate eventually. Common cases:

  • Saving a page or widget that contains scripts, embeds or code snippets
  • Uploading certain files, or importing content
  • Payment gateway webhooks and callbacks, which leave orders stuck at pending payment
  • Uptime monitors, backup services, and your own office IP after repeated failed logins
  • Country blocks that catch customers travelling abroad or using a VPN
  • Aggressive bot settings: Cloudflare's Bot Fight Mode on the free plan, for example, can interfere with webhooks and APIs and can't be bypassed with custom rules at the time of writing

To fix one, find the exact rule that fired. Cloudflare shows it in its security events, Wordfence in its live traffic and blocking logs, and your host can find ModSecurity rule IDs in the server error log. Then add the narrowest exception that works: one rule, for one URL or one trusted IP. Don't switch the whole firewall off. If you're seeing a 403 Forbidden page, fixing 403 errors on WordPress walks through which layer is blocking you.

Which setup suits your site

SiteSensible setup
Brochure site on shared hostingThe host's firewall plus one security plugin for login protection and 2FA, or Cloudflare's free plan in front
WooCommerce storeA cloud firewall with rate limiting on login and checkout, plus a plugin for logins, with webhooks tested after every change
Site under a bot flood or repeated attacksA DNS-level firewall, so the traffic never reaches your hosting
Site that has just been cleanedClean first, then firewall and login protection, with extra monitoring for a month

Avoid stacking two firewall plugins; they duplicate work and conflict. A cloud firewall and one plugin together is fine, because they work at different layers. None of this replaces updates and strong logins; see how to secure your WordPress login.

Testing your firewall after setup

A firewall that is switched on is not the same as a firewall that works. After setting one up, run a few simple checks.

  1. Confirm traffic passes through it. For Cloudflare or Sucuri, check that your DNS points to them and that the origin server's IP is not exposed in old DNS records such as a "direct" or "ftp" subdomain. Attackers who find the real IP can skip a DNS-level firewall.
  2. Test the login protection. From a phone on mobile data, try a few wrong passwords and confirm the rate limit or challenge triggers, and that your office IP is not locked out by mistake.
  3. Test the paths that matter. Place a test order, submit the contact form, and if you take payments through Razorpay or another gateway, confirm their callback URLs are not blocked. Payment webhooks blocked by a firewall are a common cause of orders stuck as pending.
  4. Check the logs for a week. Look at what is being blocked. If real customers or your own tools appear, add a narrow exception rather than turning a rule off.

Repeat these checks after major plugin changes or a move to new hosting, because new URLs and IP addresses can break rules quietly.

Quick check: is a firewall actually protecting you?

  1. Check for a cloud WAF: run nslookup -type=ns yourdomain.com or check your DNS settings. Nameservers at Cloudflare or a security provider mean traffic can pass through their firewall if it is switched on.
  2. Check the plugin: in wp-admin, open your security plugin (for example Wordfence, Firewall) and confirm the status shows the firewall enabled and, for Wordfence, whether it is in learning or enabled and protecting mode.
  3. Look at blocks: open the plugin's live traffic or blocked requests log, or the Security, Events screen in Cloudflare. Seeing blocked login attempts confirms it is working.

When to get help

Get help when your site was hacked even with a firewall, when real customers are being blocked, or when login attacks are slowing the server. WordPress malware removal includes cleanup and firewall setup, WordPress maintenance reviews blocks and updates rules, and speed optimisation checks the firewall isn't adding delay. Get in touch with your security plugin name.

FAQs

Do I need a firewall plugin if I use Cloudflare?

Not necessarily for blocking attacks, but a security plugin still helps with WordPress-aware jobs such as two-factor login, login limits and file-change alerts. Cloudflare plus one plugin is a common, sensible pairing.

Is Cloudflare's free plan enough for a WordPress site?

For many small business sites it is a good start. Stores and sites that are attacked often may benefit from a paid plan's WordPress rules and extra rate limiting.

Can I use Wordfence and Cloudflare together?

Yes. Make sure Wordfence reads the visitor's real IP address from Cloudflare's header rather than seeing every visitor as Cloudflare, or it may block the wrong addresses.

Will a firewall slow down my website?

A cloud firewall usually doesn't, and its CDN often makes pages faster. A plugin firewall adds a little work to each request, which is rarely noticeable on decent hosting.

Why is my firewall blocking me?

Usually repeated failed logins from your IP, a rule triggered by code in a page you were saving, or a country or bot setting. Find the rule in the firewall's log, then add a narrow exception.

Does a WordPress firewall stop all hacks?

No. It blocks many known attack patterns and slows down password guessing, but outdated plugins, weak passwords and stolen admin logins can still lead to a hack. Keep updates, backups and two-factor login in place alongside the firewall.

Need help with your website?

I'm a freelance WordPress developer building fast, SEO-friendly websites since 2020. Tell me what you need and I'll reply with a plan and a fixed quote, usually within 24 hours.

Found this useful? Share it:
Contact

Let's build your next website

Available for freelance projects, agency white-label work and long-term maintenance. Feel free to pass this along to your team or company.

I reply within 24 hours, usually the same day. Your details are emailed to me, then WhatsApp opens so we can chat right away.

Chat now