Tutorial

How to Set Up a WordPress Firewall (WAF) and Block Bad Traffic

A Web Application Firewall stops attacks before WordPress even loads. Here is how to configure a WAF, block bad bots and regions, and harden WordPress.

WordSec Team
June 16, 202612 min read

A Web Application Firewall, or WAF, is the front door of your WordPress security. It inspects every incoming request and blocks the malicious ones, SQL injection, cross-site scripting, remote code execution, malicious uploads, and brute-force floods, before WordPress runs a single line of code. A request that gets blocked at the firewall never reaches your plugins, your theme, or your database.

This guide explains how a WordPress firewall works and how to configure one properly using the WordSec Firewall module, then how to back it up with IP and geo blocking. The firewall and the essential rules are included on the WordSec Free plan.

What a WordPress firewall actually does

There are two broad kinds of WAF:

  • Endpoint firewalls run inside WordPress as a plugin. They are easy to install, see the full application context, and need no DNS changes.
  • Cloud or edge firewalls filter traffic before it reaches your server, which also absorbs raw flood traffic.

WordSec gives you an endpoint WAF that evaluates requests before WordPress loads, so the protection travels with your site and requires no nameserver change. Whichever model you use, the job is the same: examine each request, compare it against rules and behavior, and block what looks hostile.

Step 1: Enable the firewall in learning mode

After you install WordSec and activate your key, open the Firewall module. It has three modes:

  • Enabled: actively blocking.
  • Learning: observing traffic and recording what it would block, without blocking yet.
  • Disabled: off.

Start in learning mode for a short period. This lets the firewall map your normal traffic so legitimate requests are not blocked when you go live. Review what it flags, then switch the WAF to enabled.

The point of learning mode is confidence. You see exactly what the firewall would have blocked before it blocks anything, so switching to enabled is a non-event for your real visitors.

Step 2: Block the traffic that is never legitimate

Some sources almost never represent a real visitor. WordSec lets you block them with simple toggles:

  • Blacklisted IPs: known-bad addresses.
  • VPN, proxy, and Tor exit nodes: common origins for anonymous abuse.
  • Bad bots, AI scrapers, and vulnerability scanners: traffic that exists only to probe or copy your site.

There is also a blackhole trap: a hidden link that well-behaved crawlers obey and abusive ones do not. Anything that follows it into the trap gets banned automatically.

Step 3: Write custom rules for your site

The built-in protection covers the common attacks. Custom rules cover the patterns specific to your site. WordSec custom rules support multiple conditions, so you can match on things like request path, method, header, or IP and then block, allow, or challenge the match.

Common uses:

  • Block access to a sensitive path that should never be public.
  • Lock an admin-only area to a known IP range.
  • Stop a specific abusive pattern you see in your logs.

Every block is recorded with full request context in the firewall logs, so you can tune rules with real evidence instead of guesswork.

Step 4: Harden WordPress with one-click toggles

A firewall filters traffic. Hardening removes the weak points attackers look for once a request gets through. WordSec includes more than 25 hardening toggles. The ones worth enabling on almost every site:

  • Disable XML-RPC to remove a brute-force and amplification vector.
  • Block user enumeration so attackers cannot list your usernames.
  • Disable directory listing so your folders are not browsable.
  • Disable the file editor so a compromised admin cannot edit plugin or theme code from the dashboard.
  • Force HTTPS and block hotlinking.
  • Hide version fingerprints, error messages, and REST API links that reveal your stack.

It also adds security headers, PHP execution hardening (so uploaded files cannot run as code), and iframe protection against clickjacking.

Step 5: Control the REST API

The WordPress REST API is powerful and, left open, can leak data or expose actions you did not intend. WordSec provides role-based REST API access with allowed and blocked namespaces, so you decide which roles can reach which endpoints. You can also block disallowed HTTP methods and sensitive file access to shrink the attack surface further.

Step 6: Add IP and geo blocking

The firewall handles request shape and behavior. The WordSec Blocking module handles origin. Use it to:

  • Ban a single IP, a CIDR range, in bulk, or from an uploaded file.
  • Blacklist or whitelist whole countries and continents.
  • Turn on automatic 404 and 403 abuse protection, which bans IPs that rack up errors probing for files.
  • Apply rate limiting to endpoints under pressure.
  • Show a custom block message and keep an IP whitelist for trusted sources.

Every ban records its reason, so your block list never becomes an unmanageable mystery. If most of your malicious traffic comes from regions where you have no audience, continent-level blocking removes a large slice of it in one move.

Step 7: Verify the firewall is working

After going live, confirm the firewall is doing its job:

  1. Check the firewall logs for blocked requests and review the reasons.
  2. Watch the Live Traffic monitor to see hits filtered in real time.
  3. Make sure legitimate traffic, real users, search-engine crawlers, and your own integrations, is passing cleanly.

If you tuned with learning mode first, this step usually just confirms that everything is behaving.

Frequently asked questions

Do I need a firewall if I already have strong passwords and 2FA?

Yes. Strong passwords and two-factor authentication protect the login, but a firewall protects the rest of the site: injection attacks, malicious uploads, vulnerability scanners, and exploit attempts against plugins. The layers solve different problems, which is why a complete setup uses both. See the complete security guide for how they fit together.

What is the difference between an endpoint firewall and a cloud firewall?

An endpoint firewall runs inside WordPress and sees the full application context with no DNS changes required. A cloud firewall filters traffic before it reaches your server and can absorb raw flood traffic. WordSec provides an endpoint WAF that evaluates requests before WordPress loads.

Will a firewall block Google or legitimate bots?

No, when configured correctly. WordSec distinguishes well-behaved search crawlers from scrapers and scanners, and learning mode lets you confirm that real traffic passes before you enable blocking. You can always whitelist a specific source.

Is the WordSec firewall free?

The firewall and essential rules are included on the Free plan, along with the hardening toggles and brute-force protection. Premium and Business add advanced firewall capabilities. Compare the plans on the pricing page.

Should I block entire countries?

Only block regions where you have no legitimate audience. If your visitors and customers are concentrated in a few countries, blocking the rest removes a large share of automated abuse with no downside. WordSec supports both country and continent level blocking and whitelisting.


Put a firewall in front of your site today: install WordSec and explore every module on the product tour.