ModSecurity is a comprehensive and highly effective WAF, but out of the box it doesn’t always work with one of the more popular WordPress management services: ManageWP.
If you’re finding that ManageWP can’t connect to your site due to ModSec, this article will walk you through how to set up a server-wide exception rule that will allow these to both work together on all of the websites on your server.
Step 1: Check the Nginx Error Log and Find the Error ID
In our testing the error ID has consistently been 949110, but you may want to quickly confirm.
Locate the Error ID
To find the error ID, we need to check the Nginx Error Site Log. This article assumes that you’ve already encountered an error using ManageWP and ModSec together.
Open up your websites configuration modal inside your GridPane account, and then click through to the logs tab and open up the Nginx Site Error Log:
We’re looking for the following to identify the request that ModSec has blocked:
In it’s entirety, the error will look like this:
2020/05/16 16:28:53 [error] 13237#13237: *3665 [client 127.0.0.1] ModSecurity: Access denied with code 403 (phase 2). Matched "Operator `Ge' with parameter `10' against variable `TX:ANOMALY_SCORE' (Value: `52' ) [file "/etc/nginx/modsec/owasp/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "80"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 52)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "127.0.0.1"] [uri "/wp-load.php"] [unique_id "158964653354.518729"] [ref ""], client: 127.0.0.1, server: waas.monster, request: "POST /wp-load.php?mwprid=5ec014c4edf430.71392005 HTTP/1.1", host: "yourwebsite.com", referrer: "https://yourwebsite.com/"'
You should be able to quickly narrow down your search with the timestamp – although note that your server is likely set to UTC time as default.
Once you’ve found your error, you need to note down the ID as we’ll be using this for our exclusion rule.
In our testing above you can see that the ID is indeed the one we were expecting to find:
Step 2: Create our ManageWP Exception
First we need to open up the configuration file where we’ll add our exclusion. To do this, run the following command:
The code below contains all of the ManageWP IP addresses as per the ManageWP whitelisting page. At the very end you’ll see the “ctl:ruleRemoveById=949110”. If by chance your ID was different to the one we were expecting, replace the 949110 with the error ID you located above in step 1.
Now add your code to the very end of the file (use your arrow keys to navigate).
SecRule REQUEST_HEADERS:X-Real-IP "@ipMatch 22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199,188.8.131.52,184.108.40.206,220.127.116.11,18.104.22.168,22.214.171.124,126.96.36.199"\ "id:3,\ phase:1,\ nolog,\ allow,\ pass,\ ctl:ruleRemoveById=949110"
Writing to and saving a file in nano is a three-step process:
- Hit CTRL-O to write to the file
- Hit Enter to confirm the file you have open is the one you want to write to
- Hit CTRL-X to exit the file
Next we need to test and reload the Nginx config.
Test the config with the following command – if there are any errors do NOT continue and reload Nginx.
If no errors are present then reload Nginx with this command:
gp ngx reload
You’ve now set up your exclusion rule for ManageWP inside ModSec and you can now use the service with all of the websites on your server.
For more detailed information about using ModSec, please checkout: