[Enhancement] Block unneeded access to plugin .php files
-
So here’s an idea on some even better security. Most plugins don’t need users to access to their php files. WordPress accesses them directly. Plus, most of them are not written to block direct access, sometimes disclosing info about the server setup, and potentially opening up attack vectors.
So, block access to plugin files that don’t need it. And allow access to those that do.
Ya, this is advanced stuff, and some people may mess up their sites. But when I get dozens of 404 errors each day of scanners looking for vulnerable files, it makes you just want to block them.
The .htaccess is simple.
– Only block in plugins/themes (or other places too)
– allow css/js/jpg/etc (configurable)
– allow some plugins (which could be configurable in panel)
– A user can tell which ones they need by using the 404 block and then looking in the logs, or by things that don’t act right, obviously.
– otherwise block it (403/404/410)# Selects themes, plugins, but below we can allow some files before we actually block # Will block php, txt, json, and anything else that is not allowed below RewriteCond %{REQUEST_URI} ^/wp-content/(plugins|themes)/.* [NC,OR] # Block anything in wp-content that ends in php (remove above OR if you dont use this) RewriteCond %{REQUEST_URI} ^/wp-content/.*\.php$ [NC] # Allow these file types RewriteCond %{REQUEST_URI} !.*\.(js|css|woff|jpe?g|gif|png|bmp|svg|swf|ttf|eot|otf)$ [NC] # Allow these files to be directly accessed. Even if they are php or whatever. #RewriteCond %{REQUEST_URI} !^/wp-content/plugins/needs-direct-access/needs-direct-access\.php$ [NC] #RewriteCond %{REQUEST_URI} !^/wp-content/plugins/needs-direct-access/needs-direct-access\.json$ [NC] # Allow access to db-error.php. if you are using it RewriteCond %{REQUEST_URI} !^/wp-content/db-error\.php$ [NC] # Decide how you will block it. Note how we block regardless # of whether the file actually exists or not RewriteRule ^(.*)$ - [F] #RewriteRule ^(.*)$ - [R=404,L] #RewriteRule ^(.*)$ - [R=410,L]
Here’s a link an article I did on it, for more info and updated details:
https://www.mydigitalwalk.com/2014/04/wordpress-plugins-security/I’ve already built a list of what files some plugins need.
Oh, and it has already worked in a few cases with people trying to access a plugin that was installed, may have been vulerable, yet they couldn’t get to the actual php file. It just showed up in my error reports.
Just be sure to test your setup and make sure it works by trying to access the php files it “should” be blocking.
Matt
- The topic ‘[Enhancement] Block unneeded access to plugin .php files’ is closed to new replies.