WordPress hardening with .htaccess: what to switch on

Written by

in

WordPress hardening with .htaccess is the set of measures you wish you had put in place after the fact. The plugin gathers them in a single section. They are all off by default: you decide what to switch on. Every item says what it does and what it can break.

WordPress hardening: three concentric circles with gaps, green, teal and purple, around a dot

The WordPress hardening switches

These are the WordPress hardening switches you can turn on one at a time:

  • No PHP in wp-content/uploads, including the .phar, .phps and .pht extensions. It is the most effective protection against webshells disguised as images.
  • Directory listing disabled where there is no index file.
  • Direct access blocked to wp-config.php, .htaccess, readme.html and debug.log.
  • Custom paths to block.
  • XML-RPC disabled, a frequent target.
  • User enumeration via ?author=N blocked, because it reveals usernames.
  • Cisilino Site Defense Network: the WordPress security plugin

What can break

Not every WordPress hardening switch suits every site: XML-RPC is needed by some apps and publishing services, so if you use them, leave it as it is. The PHP block in uploads can stop a plugin that used to put code there. Blocking debug.log, on the other hand, never causes problems.

Custom paths: since version 1.0.3 the plugin never writes quotes or control characters into the rules it creates from your paths. Before, the customisation was not filtered enough and a badly written path could produce an invalid .htaccess and block the whole site. We chose the safest route: those characters are discarded silently when the rule is written. So you never have to deal with an error. In the field they stay as you typed them, but have no effect.

How WordPress hardening writes the rules

The rules end up in .htaccess. We removed the php_admin_flag directive. On PHP-FPM or CGI hosting with Apache it caused a 500 error on the whole site. Require all denied alone is enough. If you deactivate the plugin the rules disappear, reactivate it and they come back. For background, the Apache guide to .htaccess files is the reference.

A practical tip: switch on one WordPress hardening option at a time. Look at the site, run the built-in test and only then move on to the next.

Frequently asked questions

What is WordPress hardening?

The set of measures that reduce the attack surface: no PHP in uploads, sensitive files protected, XML-RPC and user enumeration closed.

Can disabling XML-RPC cause problems?

Yes, if you use apps or services that need it. In that case it is better to leave it on.

What happens to the rules if I deactivate the plugin?

They are removed from .htaccess. When you reactivate the plugin they come back as they were.

Read more

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Cookie Notice by Real Cookie Banner