How To Fix WordPress and Mod Security 2

Recently my website was moved to a new web server, and in the process the server software was upgraded, and it broke some parts of my site. It took a bit of digging but in the end I worked out that the problem lie with Mod Security – a server plugin that improves security but can sometimes inadvertently break features.

The problems I had were two fold.

  1. Elements of WordPress stopped functioning. In particular creating and editing WordPress posts, and uploading images or media stopped functioning.
  2. My BBPress forum (on Pro Theme Design) started having problems with posting replies.

The big thing that confused me is that only certain word combinations caused issues, which meant that the error was inconsistent. As I mentioned above, the problem was with Mod Security.

Mod Security (modsec)

The whole idea behind Mod Security is that it has a series of rules that are applied when different things happen on your website. When these things happen it will run through it’s rules and make sure that nothing bad is happening. This is great in theory but it relies on the fact that you don’t do certain things, and these are things that some dynamic systems need to do.

However, these rules can be disabled on a per script basis, and this formed the grounding for my fix. The way to fix the issue was to disable certain rules for certain scripts on the site, thus allowing the desired behaviors to occur.

Editing Mod Security

I am not a server guru so this took me a bit of hunting down, but eventually I worked out, that on my server, I could edit the files found in ‘/usr/local/apache/conf/modsec2‘ so that they do what I want. My solution was to edit ‘exclude.conf

Note that the location of the Mod Sec files for your server may well be different. If you are on shared hosting you may not have access to them. Most hosts will edit this stuff for you so I would suggest talking to your tech support if you’re not sure about something.

Fixing WordPress

The issues with WordPress were on the admin side. I was unable to upload photos using the media editor and I was sometimes unable to edit posts and pages. My fix was to add the following rules to exclude.conf as mentioned above.

<locationmatch "/wp-admin/admin-ajax.php">
SecRuleRemoveById 300013
SecRuleRemoveById 300015
SecRuleRemoveById 300016
SecRuleRemoveById 300017
SecRuleRemoveById 949110
SecRuleRemoveById 980130
</locationmatch>

<locationmatch "/wp-admin/page.php">
SecRuleRemoveById 300013
SecRuleRemoveById 300015
SecRuleRemoveById 300016
SecRuleRemoveById 300017
SecRuleRemoveById 949110
SecRuleRemoveById 980130
</locationmatch>

<locationmatch "/wp-admin/post.php">
SecRuleRemoveById 300013
SecRuleRemoveById 300015
SecRuleRemoveById 300016
SecRuleRemoveById 300017
SecRuleRemoveById 949110
SecRuleRemoveById 980130
</locationmatch>

Fixing BBPress

The problem with BBPress is that posting replies didn’t always work – it was causing a server error 500. It took me a while to realise ModSec was the issue with BBPress, and unfortunately the rules are not exactly the same as for WordPress.

<locationmatch "/bb-post.php">
SecRuleRemoveById 300013
SecRuleRemoveById 300015
SecRuleRemoveById 300016
SecRuleRemoveById 300017
</locationmatch>

Include the whitelist in the modsec2.conf file here – “/usr/local/apache/conf/modsec2.conf”

Include "/usr/local/apache/conf/modsec2.user.conf"

Restart apache (I used the links in my server control panel for this). And you’re done 🙂

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...
16 Sep 2016

What is the Difference Between WordPress.org and WordPress.com?

Recently, I’ve received a couple of emails asking about the difference between WordPress.com and WordPress.org versions of WordPress. The reason for the confusion is that I sell themes for both sites – and I often get people buying my themes...
13 May 2010

6 Tips to Build Better WordPress Themes

If you want to make WordPress themes, for clients, to release for free or to sell, then there are a lot of factors you need to take into consideration. Below are some hints and tips that should help ease your...
17 Oct 2012

WordPress Social Network Aggregation

I really like the idea of a Tumblog – and even have one on Tumblr.com – but I don’t promote it anywhere. Conceptually it’s great – but I don’t like not having control over my content.What I would really like...
13 Oct 2016

Lessons Learned from 20 Theme Releases on WordPress.com

In 2007 I partnered with Darren Hoyt to release Mimbo Pro, one of the earliest premium WordPress themes. In 2012 Mimbo Pro was published on wordpress.com. Last week – on October 5th 2016 to be precise – my 20th theme...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...