{"id":520,"date":"2011-07-24T23:44:38","date_gmt":"2011-07-24T21:44:38","guid":{"rendered":"http:\/\/www.tripledude.com\/?p=520"},"modified":"2011-07-24T23:44:38","modified_gmt":"2011-07-24T21:44:38","slug":"paypal-ipn-requests-and-mod_security","status":"publish","type":"post","link":"https:\/\/www.tripledude.com\/?p=520","title":{"rendered":"PayPal IPN requests and mod_security"},"content":{"rendered":"<p>I just spend some part of a week trying to successfully receive PayPal IPN requests. Sent out from the IPN simulator. I got stuck when it (the simulator) kept saying it couldn&#8217;t deliver the IPN request: Bad Request. Indeed&#8230; bad request!<\/p>\n<p>Hunting down the differences between two servers &#8212; the second one receiving the IPN requests just beautifully &#8212; I came upon the module &#8220;HttpRequest&#8221;. I can safely say that had nothing to do with it. But it did let me trigger another thought: this server uses mod_security &#8212; good for generating a ton of error messages in the log file, and, apparently, blocking IPN requests.<\/p>\n<p>So I don&#8217;t know why I didn&#8217;t check it sooner, but when I tailed the apache error logfile for the site, and triggered an IPN request from the simulator, there it was: the request was <strong>Access denied<\/strong>!<!--more--><\/p>\n<blockquote><p>[Sun Jul 24 22:46:16 2011] [error] [client 12.34.56.78] ModSecurity: Access denied with code 400 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file &#8220;\/etc\/modsecurity2\/optional_rules\/modsecurity_crs_21_protocol_anomalies.conf&#8221;] [line &#8220;48&#8221;] [id &#8220;960009&#8221;] [msg &#8220;Request Missing a User Agent Header&#8221;] [severity &#8220;WARNING&#8221;] [tag &#8220;PROTOCOL_VIOLATION\/MISSING_HEADER&#8221;] [hostname &#8220;suchanicehostname.nl&#8221;] [uri &#8220;\/paypal.php&#8221;] [unique_id &#8220;TiyEmFGrVioAAD66YgIAAAAC&#8221;]<\/p><\/blockquote>\n<p>This error message even states the file that you have to hack to overcome this! Which I did. Then, back to triggering an IPN request, trembling fingers&#8230;<\/p>\n<blockquote><p>[Sun Jul 24 22:59:56 2011] [error] [client 12.34.56.78] ModSecurity: Access denied with code 400 (phase 2). Match of &#8220;rx ^OPTIONS$&#8221; against &#8220;REQUEST_METHOD&#8221; required. [file &#8220;\/etc\/modsecurity2\/optional_rules\/modsecurity_crs_21_protocol_anomalies.conf&#8221;] [line &#8220;41&#8221;] [id &#8220;960015&#8221;] [msg &#8220;Request Missing an Accept Header&#8221;] [severity &#8220;CRITICAL&#8221;] [tag &#8220;PROTOCOL_VIOLATION\/MISSING_HEADER&#8221;] [hostname &#8220;suchanicehostname.nl&#8221;] [uri &#8220;\/paypal.php&#8221;] [unique_id &#8220;TiyHzFGrVioAAHT0S90AAAAD&#8221;]<\/p><\/blockquote>\n<p>Yep, there was another one. However: disabling this solved the issue! As specified in the above section, it came down in commenting out the next two sections in the file &#8220;modsecurity_crs_21_protocol_anomalies.conf&#8221; (and restarting apache):<\/p>\n<blockquote><p>#SecRule &amp;REQUEST_HEADERS:Accept &#8220;@eq 0&#8221; \\<br \/>\n#\u00a0\u00a0\u00a0 &#8220;chain,phase:2,skip:1,t:none,deny,log,auditlog,status:400,msg:&#8217;Request Missing an Accept Header&#8217;, severity:&#8217;2&#8242;,id:&#8217;960015&#8242;,tag:&#8217;PROTOCOL_VIOLATION\/MISSING_HEADER'&#8221;<br \/>\n#SecRule REQUEST_METHOD &#8220;!^OPTIONS$&#8221; &#8220;t:none&#8221;<br \/>\n#SecRule REQUEST_HEADERS:Accept &#8220;^$&#8221; \\<br \/>\n#\u00a0\u00a0\u00a0 &#8220;chain,phase:2,t:none,deny,log,auditlog,status:400,msg:&#8217;Request Missing an Accept Header&#8217;, severity:&#8217;2&#8242;,id:&#8217;960015&#8242;,tag:&#8217;PROTOCOL_VIOLATION\/MISSING_HEADER'&#8221;<br \/>\n#SecRule REQUEST_METHOD &#8220;!^OPTIONS$&#8221; &#8220;t:none&#8221;<\/p>\n<p>#SecRule &amp;REQUEST_HEADERS:User-Agent &#8220;@eq 0&#8221; \\<br \/>\n#\u00a0\u00a0\u00a0 &#8220;skip:1,phase:2,t:none,deny,log,auditlog,status:400,msg:&#8217;Request Missing a User Agent Header&#8217;,id:&#8217;960009&#8242;,tag:&#8217;PROTOCOL_VIOLATION\/MISSING_HEADER&#8217;,severity:&#8217;4&#8242;&#8221;<br \/>\n#SecRule REQUEST_HEADERS:User-Agent &#8220;^$&#8221; \\<br \/>\n#\u00a0\u00a0\u00a0 &#8220;t:none,deny,log,auditlog,status:400,msg:&#8217;Request Missing a User Agent Header&#8217;,id:&#8217;960009&#8242;,tag:&#8217;PROTOCOL_VIOLATION\/MISSING_HEADER&#8217;,severity:&#8217;4&#8242;&#8221;<\/p><\/blockquote>\n<p>Apparently, the IPN request does not adhere to the protocol definition. Happy PayPal-IPN-ing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just spend some part of a week trying to successfully receive PayPal IPN requests. Sent out from the IPN simulator. I got stuck when it (the simulator) kept saying it couldn&#8217;t deliver the IPN request: Bad Request. Indeed&#8230; bad request! Hunting down the differences between two servers &#8212; the second one receiving the IPN [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,47],"tags":[8,50,49,48],"_links":{"self":[{"href":"https:\/\/www.tripledude.com\/index.php?rest_route=\/wp\/v2\/posts\/520"}],"collection":[{"href":"https:\/\/www.tripledude.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tripledude.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tripledude.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tripledude.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=520"}],"version-history":[{"count":8,"href":"https:\/\/www.tripledude.com\/index.php?rest_route=\/wp\/v2\/posts\/520\/revisions"}],"predecessor-version":[{"id":528,"href":"https:\/\/www.tripledude.com\/index.php?rest_route=\/wp\/v2\/posts\/520\/revisions\/528"}],"wp:attachment":[{"href":"https:\/\/www.tripledude.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tripledude.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tripledude.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}