Skip to content
James Ross
articlePublished Updated 7 min read

Stopping XML-RPC bot floods on a shared WordPress host

By James Ross

An XML-RPC bot flood is a CPU incident, not a login attack: thousands of POSTs to xmlrpc.php each start WordPress and run PHP, so the host saturates without any account being compromised. On this cPanel host the response moved in three stages — hand-written ModSecurity rules, then blocking at nginx before Apache and PHP, then OPcache to make the requests that still arrived cheaper. The 15 WordPress sites later left the server for static hosting.

A flood of identical packets hitting a server tower with a maxed CPU gauge until an amber barrier seals one door, showing an XML-RPC bot flood.

That last move is the subject of moving 15 WordPress sites to Cloudflare Workers, which removed the endpoint instead of filtering it.

Why does XML-RPC cause CPU spikes?

XML-RPC causes CPU spikes because every call is a full WordPress bootstrap behind a POST. The request loads wp-load.php, initialises plugins and the database connection, then dispatches a method. Page caching does not help: a cache plugin serves GETs, and XML-RPC arrives as a POST.

The protocol is a remote procedure call format that predates REST and still ships in WordPress (XML-RPC specification). Its WordPress implementation supports system.multicall, which lets one HTTP request contain many method calls. That is convenient for a legitimate client syncing a batch of posts, and it is an amplifier for anyone sending junk.

Three myths are worth clearing up before choosing a fix:

  • “Disable XML-RPC in WordPress and the problem goes away.” The xmlrpc_enabled filter does not disable the endpoint. WordPress’s own documentation says it controls methods that require authentication, and that pingbacks and other unauthenticated methods are outside its scope.
  • “It is a brute-force login attack.” Login attempts hit wp-login.php and are cheap to reject. XML-RPC floods hit a different file and do more work per request.
  • “The WAF will handle it.” A WAF rule does handle it when the domains sit behind one. Before that, the request still reaches the origin.

The CPU graph is the symptom. The cause is request volume multiplied by per-request work, and the fix has to reduce one of those two numbers.

How do you confirm it is XML-RPC?

Confirm it from the access log and the per-vhost CPU, not from the WordPress dashboard. The log shows POST /xmlrpc.php at a volume no real client produces, usually spread across many addresses and a rotating user agent.

The useful evidence:

  1. Request mix. Count POSTs to xmlrpc.php against all requests over the same window. On a healthy blog network the ratio is tiny; during a flood it dominates.
  2. Source spread. A few addresses sending thousands of requests is a scraper. Thousands of addresses sending a few each is a botnet, and per-IP blocking alone will not help.
  3. Response codes. A flood often produces a long run of 200s followed by 500s as PHP-FPM pools saturate. That shape points at PHP work, not bandwidth.
  4. Per-vhost CPU. If one account’s PHP-FPM pool is pinned while the others are idle, the problem is inside that account, not the network.

Distinguish it from admin-ajax.php, which legitimate themes and plugins use heavily. Blocking admin-ajax.php breaks sites; blocking xmlrpc.php usually does not, because most sites have no client that needs it.

Layer 1: ModSecurity rules

ModSecurity rules were the first layer because the web server already had the module loaded. A rule can inspect the request line, method and body, then deny before WordPress runs.

On this host the catch was that ModSecurity had no vendor ruleset. The OWASP Core Rule Set is what normally supplies the signatures and virtual patching (OWASP CRS documentation); without it, every rule is hand-written. A hand-written rule for POST /xmlrpc.php is easy. The next variant — a different path, a query string, a chunked body — is not, and the person writing rules is also the person debugging false positives.

ModSecurity also sits inside Apache in this stack, so a denied request still paid for Apache, the module and the rule evaluation. That is cheaper than a full WordPress bootstrap and more expensive than rejecting at the front.

ModSecurity stayed available for rules nginx cannot express. The main block moved forward.

Layer 2: blocking at nginx

Blocking at nginx rejects the request before it reaches Apache or PHP, which is the cheapest place to say no short of the edge. The host already ran nginx in front of Apache for cPanel, so there was a place to cut.

    # reject XML-RPC before the proxy passes it to Apache
location = /xmlrpc.php {
    return 444;
}

return 444 is an nginx-specific code that closes the connection without sending a response header (nginx rewrite module). It is cheaper than a 403 and gives a bot less to react to. A 403 is the better choice when a real client might exist and you want it to see a clear refusal.

For endpoints that cannot be blocked outright, rate limiting is the next tool. limit_req caps requests per key per second with a burst allowance (nginx limit_req), and map builds the key from the request method, URI or user agent (nginx map). A common shape is: block xmlrpc.php outright, rate-limit wp-login.php, and leave admin-ajax.php alone unless it is clearly abused.

Two operational details decide whether this survives a cPanel update. The rules belong in an include that the panel does not regenerate, and every change runs nginx -t before a reload. A syntax error in a vhost include takes every site on the server down at once, not just the one being protected.

Layer 3: OPcache

OPcache lowers the CPU cost of each PHP request by keeping compiled bytecode in shared memory, so PHP does not parse and compile the same files on every hit (OPcache). It does not reduce the number of requests, and under a flood it only buys headroom.

The settings that matter on a PHP-FPM host:

  • opcache.memory_consumption sizes the shared memory segment. Too small and the cache thrashes, evicting scripts it will need again.
  • opcache.max_accelerated_files caps how many scripts fit. A plugin-heavy WordPress install has thousands of files.
  • opcache.validate_timestamps controls whether PHP checks file timestamps. Leaving it on costs a stat per request; turning it off requires an FPM reload on every deploy.
  • One cache per pool. FPM workers in the same pool share the segment; separate pools do not.

On a cPanel host with EasyApache, each PHP version has its own ini tree, so a drop-in has to land in the right version’s conf.d and the matching FPM service has to reload (OPcache configuration). That is routine until the handler changes under load, which is where the outage below came from.

Where should the block live?

The block belongs as far from PHP as the traffic allows. Each layer saves a different amount of work, and each has a different failure mode.

Layer Runs before Saves False-positive risk Best use
Cloudflare WAF custom rule (Cloudflare custom rules) The origin sees nothing Origin CPU and bandwidth Low if scoped to one path Domains already behind Cloudflare
nginx return/limit_req Apache and PHP Apache and PHP work Low for xmlrpc.php The origin’s front door
ModSecurity WordPress WordPress bootstrap Higher without a vendor ruleset A backstop, or where nginx cannot be changed
WordPress filter The method dispatch Some methods only Low, but incomplete Defence in depth, never the only control

Which should you choose? Put a path block at the edge if the domain is proxied, and at nginx if it is not. Keep ModSecurity for the rules you cannot express as a path, and never rely on the WordPress filter as the primary control — its own documentation says it is narrower than the name suggests.

What broke and what we changed

ModSecurity without a ruleset was a hobby, not a defence. Hand-written rules cover the patterns you think of; a flood that changes shape walks past them. The move to nginx was the real fix because it stopped the request before Apache, and it did not depend on someone guessing the next payload shape.

A PHP configuration change is not free. A handler change on a busy site restarted FPM asynchronously, and the first attempt produced about one to two minutes of 503s before the pool came back. The fix was to restart the matching php-fpm service explicitly after the change instead of trusting the panel to do it. The same rule applies to an OPcache drop-in: reload the pool deliberately and watch it come back. On a host with paying customers, that is the difference between a change window and an incident.

The filter was not an off switch. Turning off XML-RPC in WordPress left pingbacks and unauthenticated methods reachable, because that is what the filter actually controls. The endpoint only disappeared when the request stopped reaching PHP, and later when the sites became static and /xmlrpc.php returned 403 at the edge.

Mail shared the host. The server also carried catch-all mail for eight blog domains. A network-level block on an address range would take mail with it, which is one reason to block the HTTP request instead. That constraint is easy to miss when the web server and the mail server share an IP.

Frequently asked questions

Is XML-RPC still needed in WordPress?

For most sites, no. The block editor uses the REST API, and most modern publishing tools have followed. Some older plugins, pingback clients and legacy integrations still call XML-RPC. Check the access log for legitimate clients before blocking it, and keep an allowlist if one exists.

Does disabling XML-RPC in WordPress stop the attack?

Not completely. The xmlrpc_enabled filter only covers methods that require authentication, and WordPress documents that pingbacks and other unauthenticated methods remain. Blocking the request at nginx or the edge is the complete control, because the request never reaches the PHP code that dispatches methods.

ModSecurity or nginx for blocking?

Nginx, when the goal is to save CPU. A rejection at nginx happens before Apache and PHP, while ModSecurity runs inside Apache and still pays for the request to get there. ModSecurity is useful when you need body inspection or a rule that nginx cannot express. Without a vendor ruleset, its value is limited.

Does OPcache help during an XML-RPC flood?

It helps, but it does not fix the flood. OPcache removes the compile step from each request, so the same volume costs less CPU. It cannot reduce the number of requests, and a flood large enough to saturate the pool will still saturate it. Treat OPcache as headroom, not as a control.

Why not just block the source IPs?

Because a distributed flood has thousands of them, and the addresses change. Blocking a few heavy senders helps briefly; blocking ranges risks real users and, on a shared host, mail delivery. Path-based blocking scales better because it does not depend on knowing who is sending.

What about wp-login.php and admin-ajax.php?

wp-login.php is worth rate-limiting and blocking, but it is cheap to reject and rarely the CPU driver. admin-ajax.php is used by legitimate themes and plugins, so a blanket block breaks sites; rate-limit it and watch the logs. xmlrpc.php is the rare endpoint that most sites can block outright.

Did moving the sites to static hosting fix it?

Yes, in the sense that the endpoint stopped existing on the origin. The 15 WordPress sites became static Astro bundles on Cloudflare Workers, so requests for /xmlrpc.php now return 403 at the edge and never reach PHP. Filtering was a holding pattern; removing the PHP surface was the fix.