Disable and secure xmlrpc.php against brute-force attacks
xmlrpc.php is WordPress’ old remote API, older than the REST API: external applications can publish posts, manage comments, upload media and check credentials with XML requests. The security problem: it is a second login door next to wp-login.php. A custom login URL or a captcha on the login page does not cover it, and its pingbacks are abused to flood other sites. WordPress enables XML-RPC by default and has no setting to turn it off.
Problem: The access log shows thousands of POST requests per hour to /xmlrpc.php, many of them system.multicall calls packed with username and password pairs, from rotating IPs. Since WordPress 4.4 only the first wrong password in a request is checked, but every request still starts PHP and WordPress, and the CPU load grows. The site does not use Jetpack, the mobile app or any XML-RPC client.
Solution: Block xmlrpc.php in the web server so PHP never runs, disable XML-RPC in WordPress as a second layer, and remove the pingback header. If some XML-RPC client is needed, remove only the dangerous methods instead.
Block it in the web server
Nginx, inside the server { } block:
location = /xmlrpc.php {
return 403; # or 444 to close the connection without a response
}
Apache, in .htaccess outside the WordPress block (as in protecting wp-config.php and xmlrpc.php):
<Files "xmlrpc.php">
Require all denied
</Files>
The request ends at the web server: no PHP worker, no WordPress bootstrap, no database query.
Disable it in WordPress
As a fallback in case the server rule is lost (a migration, a new server block), a must-use plugin, wp-content/mu-plugins/disable-xmlrpc.php:
<?php
// Methods that require authentication return an error before any password is checked
add_filter( 'xmlrpc_enabled', '__return_false' );
// Pingbacks do not need a login, so remove those methods too
add_filter( 'xmlrpc_methods', function ( $methods ) {
unset( $methods['pingback.ping'], $methods['pingback.extensions.getPingbacks'] );
return $methods;
} );
// Do not advertise the endpoint
add_filter( 'wp_headers', function ( $headers ) {
unset( $headers['X-Pingback'] );
return $headers;
} );
remove_action( 'wp_head', 'rsd_link' );
With xmlrpc_enabled false, a multicall full of login attempts gets an error for each of them without WordPress checking a single password, so brute force through XML-RPC is impossible even if the request reaches PHP.
If an XML-RPC client is needed
Jetpack still uses XML-RPC for its connection. Then do not block the file and do not use xmlrpc_enabled; remove only the pingback methods:
<?php
add_filter( 'xmlrpc_methods', function ( $methods ) {
unset(
$methods['pingback.ping'], // abused for DDoS reflection
$methods['pingback.extensions.getPingbacks']
);
return $methods;
} );
system.multicall and system.listMethods cannot be removed with this filter: the XML-RPC server adds them after it runs, so an unset() for them does nothing. For passwords that is no longer a problem: since WordPress 4.4 a request checks at most one wrong password, the rest of a multicall gets an error. Login attempts through XML-RPC still count as failed logins, so a login limiter that hooks wp_login_failed sees them.
Alternatively, allow xmlrpc.php in the web server only for the IP ranges Jetpack publishes in its documentation. For your own integrations, the REST API with Application Passwords is the modern replacement for XML-RPC.
Check
curl -s -o /dev/null -w "%{http_code}\n" -X POST https://example.com/xmlrpc.php
# 403 when blocked in the server
curl -sI https://example.com/ | grep -i x-pingback
# no output: the header is gone
NOTE: Blocking XML-RPC also turns off pingbacks (incoming notifications that another site linked to you), which most sites do not miss. The WordPress and WooCommerce mobile apps work through the REST API today and are not affected. If the attacks continue on wp-login.php after XML-RPC is closed, add a ban on the server level, see Fail2ban for WordPress.