Skip to content

WordPress brute-force defense: layers beyond a plugin

WordPress brute-force protection that lives only in a plugin is the last line of defense. The four layers in front of the plugin that actually carry the traffic, and the metrics that prove each one is doing work.

A WordPress site that relies on a security plugin alone to stop brute-force traffic is asking the wrong layer of the stack to do work that should never reach it. Every failed login attempt that hits the plugin already consumed a PHP process, a database query, and a few milliseconds of WordPress bootstrap. At the volumes a public WordPress site sees — thousands of attempts per day on a small site, hundreds of thousands on a popular one — the plugin doing the work is the plugin holding the rest of the site back. Brute-force defense belongs in front of WordPress, not inside it.

What’s happening

A brute-force login attempt against a WordPress site flows through layers, each of which can stop it. From outside-in:

  1. DNS / CDN (Cloudflare, Fastly, Sucuri WAF). The edge sees the request first. A WAF rule that blocks the bad IP, the bad country, or the bad rate stops the request before it touches your infrastructure.
  2. Origin firewall (iptables, ufw, the cloud security group). The host-level firewall stops anything that bypassed the CDN by hitting the origin IP directly.
  3. Web server (nginx or Apache). Server-level rate limiting on specific paths catches what the WAF missed.
  4. PHP / WordPress core. The WordPress wp-login.php handler.
  5. Security plugin. The last layer, the layer that runs WordPress code.

A defensive architecture spreads the work across layers. The plugin is for the residual traffic that made it past everything else — typically less than 1% of total attempt volume.

How to verify

Quantify the traffic at each layer for a sample week:

# Cloudflare: dashboard analytics shows blocked requests by rule
# Look for the "wp-login.php" path block count over 7 days

# Origin firewall: how many connections were dropped at the IP layer
sudo iptables -L INPUT -v -n | grep DROP

# Web server: how many requests to wp-login.php reached the access log
awk '$7 ~ /wp-login\.php/ && $9 ~ /^[45]/' /var/log/nginx/access.log | wc -l

# WordPress: how many login attempts the security plugin recorded
wp db query "SELECT COUNT(*) FROM wp_wfHits \
  WHERE ctime > UNIX_TIMESTAMP(NOW() - INTERVAL 7 DAY) \
  AND action = 'blocked:waf';"

# Or for Solid Security
wp db query "SELECT COUNT(*) FROM wp_itsec_logs \
  WHERE timestamp > NOW() - INTERVAL 7 DAY AND module = 'brute-force';"

A healthy distribution: 95%+ of attempts blocked at CDN, 4% at web server, 1% at the plugin. An unhealthy distribution: 100% reaching the plugin because the upstream layers are not configured.

The fix

Configure each layer with appropriate rules.

  1. CDN / Cloudflare layer — primary defense. The rules from the Cloudflare WAF patterns KB:

    # Rate-limit POST to wp-login.php
    Expression: http.request.uri.path eq "/wp-login.php" and http.request.method eq "POST"
    Rate: 5 per minute per IP
    Action: Block for 10 minutes
    
    # Same for xmlrpc.php
    Expression: http.request.uri.path eq "/xmlrpc.php"
    Rate: 10 per minute per IP
    Action: Block for 10 minutes
    
    # Bot challenge on login
    Expression: http.request.uri.path eq "/wp-login.php" and cf.client.bot and not cf.verified_bot
    Action: Managed Challenge

    Optional: country-based block. If your administrators only log in from a small set of countries, block the rest on login paths.

  2. Origin firewall layer — secondary defense. Drop connections from IPs that should never reach the origin:

    # Allow only Cloudflare IPs to reach the web server on 443
    # /etc/iptables/rules.v4
    *filter
    :INPUT DROP [0:0]
    :FORWARD DROP [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p tcp --dport 22 -s <your-management-IPs> -j ACCEPT
    -A INPUT -p tcp --dport 443 -s 173.245.48.0/20 -j ACCEPT
    -A INPUT -p tcp --dport 443 -s 103.21.244.0/22 -j ACCEPT
    # ... full Cloudflare IP list from cloudflare.com/ips-v4.txt
    COMMIT

    This stops any attempt to bypass Cloudflare by hitting the origin IP directly. Update the rule when Cloudflare adds new ranges.

  3. Web server layer — tertiary defense. Nginx rate limiting:

    # /etc/nginx/conf.d/wp-login-rate.conf
    limit_req_zone $binary_remote_addr zone=wplogin:10m rate=5r/m;
    
    server {
        location = /wp-login.php {
            limit_req zone=wplogin burst=10 nodelay;
            # ... PHP-FPM handler
        }
        
        location = /xmlrpc.php {
            limit_req zone=wplogin burst=10 nodelay;
            # ... PHP-FPM handler
        }
    }

    This catches anything that the WAF missed because the WAF rules did not match or because the attacker found a way through. The thresholds are aggressive — legitimate humans rarely exceed five login attempts per minute.

  4. WordPress layer — last line of defense. The security plugin’s brute-force lockout works fine at this volume. Configure as documented in the plugin-specific KBs (Wordfence baseline, Solid Security essentials).

  5. Configure 2FA for everyone in the admin role. A brute-force attack that succeeds on the password but fails on the 2FA challenge is not a compromise. 2FA is the floor for any account with administrator capability.

  6. Measure the layer distribution. Run the verification commands every week. If the plugin layer is doing more work than 1% of total attempts, the upstream layers need tuning. Two patterns:

    • The CDN block is not catching enough — check rule expression and that the rule is actually enabled.
    • The origin IP has leaked — attackers are bypassing the CDN. Rotate the origin IP and lock down to Cloudflare ranges (step 2).
  7. Tarpit instead of block (advanced). Returning a 200 with a slow response is sometimes more effective than 403 — the bot’s timeout queue fills up and it gets less efficient at attacking. Nginx config:

    location = /wp-login.php {
        if ($request_method = POST) {
            # ... rate limit logic above
            # Then tarpit: slow respond instead of block
        }
    }

    This is optional. The simpler approach (block) is fine for most sites.

  8. CAPTCHA on the login form as fallback. If you cannot deploy IP allowlisting (admins login from variable IPs and you do not want to maintain the list), add CAPTCHA to the WordPress login form. The hCaptcha or Cloudflare Turnstile plugins integrate cleanly. CAPTCHA is unpopular with users but cheap defense.

A WordPress site with brute-force defense layered across CDN, firewall, web server, and plugin has a login endpoint that survives the next big credential-stuffing wave without alerting on every attempt. Stack Harbor configures this layered defense as part of enterprise WordPress support onboarding, including the per-layer dashboards that show the distribution working as intended. If your WordPress site’s only brute-force defense is a plugin and you have noticed the access log filling up, book the WAF and layered defense pass.