10 releases in 8 days: what outside checks found in HelloAdmin Guard
I released HelloAdmin Guard on GitHub on November 17. If you think I only write the plugin, you are wrong: it also gets checked for holes, by me, by the wordpress.org review team and by outside reviewers. That is why there have been 10 releases since the launch. Some had plain bugs, some had real holes. Here is what we found and how I fixed it.
Problem: a security plugin that closes a hole in the obvious place and leaves it open one step to the side gives a false sense of safety. That is worse than no plugin, because the site owner stops looking.
Solution: check every rule from the outside, the way a bot would, then try the variants: another letter case, another host name, another file name, another login route. Below are the cases where a variant got through, in the order of how much they surprised me.
The user list was still open as /wp/v2/USERS
“Hide user names” closes the REST API user list for visitors who are not logged in. The plugin compared the route as written, in lower case. The WordPress REST server matches routes in any letter case, so the same list answered under a different spelling:
curl -s https://example.com/wp-json/wp/v2/users # closed curl -s https://example.com/wp-json/wp/v2/USERS # before 0.5.1: the full user list
The fix is one letter in the pattern, the “i” at the end:
if ( preg_match( '#^/wp/v2/users(/|$)#i', $request->get_route() ) ) {
The status check in the plugin now also requests /wp/v2/Users, so a regression shows up on the settings page. Two more places gave away the login: oEmbed answers carry author_name, and comments of registered users get the class comment-author-<login>. Both are cleaned now. More on why user names matter: how to stop username enumeration.
The https redirect trusted any host name
The http to https rule built its target from the Host header. On a server that answers any host name pointed at it, a request with a foreign Host got a 301 to that foreign name. The rule now runs only for the site’s own names from home and siteurl, with or without www:
RewriteCond %{HTTP_HOST} ^(www\.)?(example\.com)(:[0-9]+)?$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The same idea fixed the self-check. After writing .htaccess the plugin opens the home page to make sure the site still works, and it followed any redirect. Now it follows redirects only to its own host. A redirect anywhere else counts as an answer and stops there.
Application passwords skipped the login limit
This one came from the wordpress.org review. A login with an application password (REST API, XML-RPC) does not go through the authenticate filter or wp_login_failed, so failed attempts were neither counted nor locked. Two other hooks cover that route:
add_action( 'wp_authenticate_application_password_errors', array( $this, 'refuse_locked_app' ) ); add_action( 'application_password_failed_authentication', array( $this, 'count_app_failure' ) );
An XML-RPC failure fires both the old and the new action, so it is counted once, not twice.
File rules that looked right and missed
The “block” rules for uploads, logs and backups were correct for the names I had in mind. Real servers have other names:
- shell.php.jpg in uploads. On servers set up with AddHandler a file with .php anywhere in the name runs as PHP.
- error_log.1, php_errorlog and numbered .log copies, not only error_log.
- Backups as .sql.xz, .sql.bz2, .dump, .jpa (Akeeba), plus wp-content/wpvividbackups and wp-content/backwpup-* folders.
- Thumbs.db, desktop.ini and __MACOSX folders that end up on the server from zip archives.
One rule was too wide the other way: the wp-config backup rule closed /wp-config-tips, a normal post address without the trailing slash. It now needs a dot after the name.
A custom admin role nobody noticed
“E-mail me about new administrators” watched the Administrator role. An account with a custom role called “adm1n” that holds manage_options, or an editor with install_plugins added to the account itself, has the same power and went unnoticed. The check now reads every role that holds one of the dangerous rights (manage_options, promote_users, edit_plugins, activate_plugins, install_plugins, unfiltered_upload) straight from the database, plus rights added to single accounts.
Security headers that nobody sent
When the plugin writes its header rules to .htaccess, PHP stops sending the same headers, so they do not come twice. But if mod_headers is off, or someone removed the rules by hand, the server sent nothing and PHP thought the server did. Now the server rules also set a request header, and PHP skips its headers only when that request header is really there.
What a plugin cannot fix
One core file, /wp-admin/upgrade.php, runs before normal plugins load, so no plugin can change how it answers. What it can give away is the WordPress version number, nothing more. If you update the database with WP-CLI anyway (wp core update-db), you can close that file on the server and forget about it. I would rather say this openly than pretend the plugin covers everything.
What I take from this
- Every rule gets an outside check, and the check tries the variants, not only the textbook request.
- Letter case, host names and file name tricks are where the gaps hide.
- A finding from a reviewer goes into a release the same day, with a line in the changelog.
The plugin is free and stays free: HelloAdmin Guard on GitHub. The full list of changes is in its CHANGELOG. If you find something it misses, tell me, it will be in the next release.