{"id":101,"date":"2007-06-13T12:59:33","date_gmt":"2007-06-13T02:59:33","guid":{"rendered":"http:\/\/www.thunderguy.com\/semicolon\/2007\/06\/13\/wordpress-vs-mod_security\/"},"modified":"2007-06-15T20:34:06","modified_gmt":"2007-06-15T10:34:06","slug":"wordpress-vs-mod_security","status":"publish","type":"post","link":"https:\/\/thunderguy.com\/semicolon\/2007\/06\/13\/wordpress-vs-mod_security\/","title":{"rendered":"WordPress vs. mod_security"},"content":{"rendered":"<p>WordPress blog posts with certain words in them can sometimes be blocked or fail mysteriously. Sometimes the offending word is silently removed from the post; other times the post fails with an HTTP error. Here&#8217;s a description of one possible cause, together with a useful workaround in case this problem happens to you. The problem could actually affect any blog platform or pretty much any other web application, not just WordPress.<\/p>\n<p>If I try to write a WordPress blog post containing the word &#8220;python&#8221; followed by a space, I get an HTTP error page. The error is &#8220;403 &#8211; Forbidden&#8221;. After a bit of experimentation I have found that the &#8220;python&#8221; can be in any case, and that it&#8217;s only a problem if followed by a space.<\/p>\n<p>By some coincidence, I recently read about a <a href=\"http:\/\/wordpress.org\/support\/topic\/29970\">similar mysterious bug<\/a> on the WordPress support forum. The problem seems to be caused by over-zealous <a href=\"http:\/\/www.modsecurity.org\/\">mod_security<\/a> rules. It looks as if my web host is using mod_security to block any HTTP POST that appears to contain a <a href=\"http:\/\/www.python.org\/\">Python<\/a> command. Even if it&#8217;s only me trying to write a blog post about scripting languages.<\/p>\n<p>Even though my problem was with the word &#8220;python&#8221;, the forum post mentions similar problems with the words &#8220;compress&#8221; and &#8220;curl&#8221;. It just depends on what rules your web host has implemented.<\/p>\n<p>I know better than to try to get my host to change their rules &#8212; it would take a bit of time, and there&#8217;s a workaround anyway. Just add some obfuscatory HTML to avoid triggering the rule. My first attempt was this:<\/p>\n<p>&#8220;<code>Python&amp;#32;<\/code>&#8221;<\/p>\n<p>This works fine, but unfortunately WordPress actually translates the <code>&amp;#32;<\/code> into a space. Later, if I edit the post and try to save, mod_security blocks it again. I have to manually replace the space with a <code>&amp;#32;<\/code> again.<\/p>\n<p>So here&#8217;s the best solution I found.<\/p>\n<p>&#8220;<code>Python&lt;span&gt;&lt;\/span&gt; <\/code>&#8221;<\/p>\n<p>Note that you have to be in the code editor (not the visual editor) in WordPress to enter the &lt; and &gt; characters. Using this trick you can talk about Python<span><\/span> just as much as you want, and edit your posts too. And this solution is completely general; you can write <code>com&lt;span&gt;&lt;\/span&gt;press<\/code> or <code>cu&lt;span&gt;&lt;\/span&gt;rl<\/code> or whatever other forbidden word you like.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress blog posts with certain words in them can sometimes be blocked or fail mysteriously. Sometimes the offending word is silently removed from the post; other times the post fails with an HTTP error. Here&#8217;s a description of one possible cause, together with a useful workaround in case this problem happens to you. The problem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[2,18,83],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-coding","tag-web-development","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":0,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"wp:attachment":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}