r/Wordpress • Jack of All Trades • 7d ago

New Security Plugin for WordPress

Hey everyone! I came up with yet another simple way to protect my and client WordPress sites. One of the simplest and super effective way is to put /wp-admin/ and wp-login.php behind basic authentication. admin-ajax.php should be excluded though because it's used in the public site for ajax stuff even though it's in /wp-admin/

So my idea is that even if someone manages to create an administrator account, they still won't be able to log in or perform any administrative actions until they are approved/trusted.

I manually approve/flag high privileged users such as Store Manager (WooCommerce), Editor or Administrator roles via WP-CLI (I could easily add a UI for this though).

Should I release this as a free/paid plugin? Anyone interested in testing it?

Just a heads-up: you might accidentally lock yourself out and it will require adding some lines to wp-config via FTP or file manager via the control panel 😃

I also made it so if anything important changes in the WordPress site like admin email that automatically deactivates the trust of the users e.g. a site is hacked and the admin email is changed that blocks access to all high privileged accounts for security reasons.

Slavi

0 Upvotes

36 comments sorted by

10

u/JeffTS Developer/Designer 7d ago

Why would you need a plugin for this? You can generally just password protect the wp-admin folder, and individual files, via either your hosting panel or by changing .htaccess.

5

u/jhkoenig 7d ago

This

Blocking access to certain files in .htaccess is a solid line of defense. The attacker never reaches your code.

1

u/nuestras 7d ago

You can, but you are assuming everyone using WordPress has the knowledge to do so, they dont.

0

u/lordspace Jack of All Trades 7d ago

I do have several layers of protection already but wanted to come up with another layer just in case there's a bug in rest API

0

u/lordspace Jack of All Trades 5d ago

what happens when somebody gains control via rest api ?

1

u/JeffTS Developer/Designer 5d ago

Wordfence and Cloudlfare both offer protection for the rest API.

-1

u/lordspace Jack of All Trades 5d ago

Sure. what if the attacker manages to create an admin account? then what?

-2

u/lordspace Jack of All Trades 7d ago

yes. that's a solid protection. did you remember the attacks from a few months ago that somebody was able to create admin accounts via WP REST api ?

A protection like this would block REST api access too.

That's a 3rd, 4th, or 5th layer of defense and not the first one of course.

2

u/Nazmussakib06 7d ago

Love the trust reset on the admin email change. Just make sure application passwords and XML-RPC are covered too, since they skip wp-login.php. Happy to beta test!

2

u/lordspace Jack of All Trades 5d ago

Thanks! I have blocked access to xmlrpc.php file on all of my sties but maybe it's worth also checking that too and adding extra checks in the plugin in case other site's are not blocking it.

2

u/Natebald603 7d ago

I like the idea, especially automatically revoking trust when the admin email changes. A few things I'd want before putting it on client sites: a recovery path that doesn't need FTP (a WP-CLI command or an mu-plugin switch), a log of every trust change (who approved whom, and when), and a check that REST and cron requests still work behind the basic auth. Happy to test it on a staging site if you release it.

1

u/lordspace Jack of All Trades 7d ago

Thanks. The log is a really good idea

1

u/ivicad Jack of All Trades 7d ago

On the log: an activity log plugin (I keep one on every site) already records role changes and a change of the admin email address, with the user and IP behind each. It won't see the approvals inside your plugin, though, unless your plugin writes them to that log.

1

u/CmdWaterford 7d ago

Are you enforcing the trusted-user restriction at the WordPress capability level, including REST API and AJAX requests, or are you primarily restricting access to wp-admin and wp-login.php?

0

u/lordspace Jack of All Trades 7d ago

At the moment it's a user meta flag that includes a number of site variables. At the moment the login action is checked. If login is done via ajax it should be handled too. For the wp-login.php and wp-admin I usually put them behind basic authentication with the exception of admin ajax file as it's used for ajax stuff on the public side too

1

u/CmdWaterford 7d ago

Interesting approach, but isn't checking trust only during login insufficient? What happens if an attacker uses the REST API with Application Passwords, or an existing administrator session remains active after trust is revoked?

Wouldn't it be more effective to enforce trust at the capability level using user_has_cap, rather than relying on authentication hooks alone?

Also, how do you protect the user meta trust flag itself from manipulation?

1

u/atvvta 7d ago

I don’t understand so your security is you put another password authentication in front of work admin?

1

u/lordspace Jack of All Trades 7d ago

The protection is only trusted accounts are allowed to login. If there's a plugin that adds an account without your knowledge it will be not trusted by default and can't login until you approve it

1

u/garliconionbee 7d ago

If they get accidentally locked out. How would they recover access?

0

u/lordspace Jack of All Trades 7d ago

The plan is to have them add a a line in their wp-config.php file to temporarily allow access

1

u/Aggressive_Ad_5454 Jack of All Trades 2d ago

Security plugin? Sounds good. But I strongly suggest you figure out how to rigorously test it.

1

u/lordspace Jack of All Trades 2d ago

well, the worst thing it can happen is to block all high privileged users as designed.
then 1 line and temporarily allow the user(s) to login back in .. but if an attacker compromises the site and changes important variables all is locked out. Even the rest api calls

1

u/babelmonk 7d ago

Nice idea, and the ā€œtrust drops when the admin email changesā€ part is clever. A couple of things I’d think about before releasing it, from running something similar at the hosting level.

A gate on wp-admin doesn’t stop a hijacked session or an application password. Once someone has a logged-in cookie or an application password, admin-ajax and the REST API do most of what wp-admin does, and you’ve had to leave admin-ajax open. That matters most on page-builder sites. Elementor and Breakdance editors save pages through admin-ajax and the REST API, so a stolen editor session can rewrite every page without ever touching your basic-auth prompt. Gate the sign-in, and treat new application passwords as an alert.

Gating paths also misses more than you’d think. Page builders don’t all live under /wp-admin/. Breakdance’s builder is the site root with a query string (/?breakdance=builder&id=…): the page is served to anyone, and permissions are only checked on its ajax calls. Elementor’s editor also leans on non-standard URLs. WordPress also uses different cookies for wp-admin and the front end, so a builder can fail to load or save even when wp-admin works. On my sites, an MU plugin looks at each request (the query string, whether there’s a front-end login, the identity token from the proxy) and sends people through the gated sign-in only when they need it. Early on I tried gating /wp-admin/ but not /wp-json/, and the block editor broke in strange ways. Gate the sign-in, then let WordPress’s own session do the rest.

And no single layer should be the plan. On the sites I host:

  • Nothing is directly reachable. The sites have no public IP; every request comes through Google’s load balancer.

  • A WAF sits in front (Cloud Armor), blocking SQL injection and scanners. It can also make one site read-only at the edge within minutes. I did exactly that for one site during last month’s PHP2Shell attacks, while every other site kept taking form submissions.

  • Sign-in goes through Google’s Identity-Aware Proxy. Only the client’s named Google accounts can even reach wp-login.php, with Google’s 2-step verification. WordPress takes the user’s identity only from the signed token IAP issues, and the WAF drops any request arriving with forged identity headers.

  • Each site is sealed off. Every site runs in its own containers with its own database login and its own files. PHP is locked to its own folder, and nothing runs as root.

  • Restarts and backups clean up. Containers start fresh from a known-good image, and nightly backups go to storage the site itself can’t change or delete.

Your plugin would be a decent extra layer on shared hosting, where most of the above isn’t available. I’d just sell it as one layer, not the entire stack.

1

u/lordspace Jack of All Trades 5d ago

Thanks! will make a note to explore stolen session cookies too.
I use more signals to invalidate the trusted users. it will be a pain in the neck when an issue happens but that would be a nice self lock so bad actors won't be able to do anything via the UI.

-1

u/Juice-Surge-Deluxe 7d ago

Did you do all of this yourself or is it implemented by your host? This is really great!

1

u/babelmonk 7d ago

Myself - on GCP using DevOps and quite a lot of automation. I'm aiming to bring 'proper' enterprise techniques to the SMB space and build up credibility that way. I have a few starter customers via word of mouth but recently have been working on growing the business as a commercial concern over time.

0

u/showbizusa25 7d ago

Interesting approach. Have you tested what happens when an admin account is compromised through an existing session rather than a new login? I'd also be interested in how the plugin handles WP-CLI recovery and avoids locking out legitimate administrators.

1

u/lordspace Jack of All Trades 5d ago

When a trusted user's password is changed regardless who did it that also invalidates the trust status and I force log out the user. Maybe I should delete all of their sessions too!

1

u/showbizusa25 5d ago

Yeah, invalidating all active sessions after a password change would be worth considering.

The scenario I was thinking about is slightly different though: an attacker steals an existing authenticated session cookie and uses it without changing the password. Would your plugin detect that, or would the session remain trusted?

Also curious whether you've tested recovery through WP-CLI if an admin accidentally gets locked out.

1

u/boltsandbytes 1d ago

A plugin is not the way for this , do it directly with nginx / apache . The next generation of malware do not use wp-login.php , they simple create the session and users.

A better way is to lock down wp-admin with Zero trust ( add a whitelist rule for admin-ajax.php )

1

u/[deleted] 7d ago

[removed] — view removed comment

1

u/lordspace Jack of All Trades 7d ago

I used to block rest API but it seems it's used in the block editor so I had to do some checks via a plugin and can't block it at web application firewall