Blogs & Stories

SpiderLabs Blog

Attracting more than a half-million annual readers, this is the security community's go-to destination for technical breakdowns of the latest threats, critical vulnerability disclosures and cutting-edge research.

ModSecurity Request Body Parsing: Recent Bypass Issues


ModSecurity is an open-source web application firewall (WAF) engine maintained by Trustwave. This blog post discusses multiple input interpretation weaknesses in the ModSecurity project. Each input interpretation weakness could allow a malicious actor to evade some ModSecurity rules.

Both ModSecurity v2 and ModSecurity v3 were affected. The issues have been addressed in v2.9.6 and v3.0.8, respectively.


Earlier this year an independent bug bounty program occurred with a primary focus on OWASP ModSecurity Core Rule Set (CRS), which is managed separately from the ModSecurity engine. Multiple issues separate from CRS were identified by Jan Gora (terjanq), with the information subsequently being passed on to the ModSecurity team. Thank you to the bug bounty hunter for the findings. Thanks also to our collaborators at CRS for their contribution, which included some additional validation of the completed fixes.

None of these issues created a direct vulnerability to either ModSecurity or any web server it is protecting. However, each resulted in the opportunity for a malicious user to evade some ModSecurity rules, hence weakening overall WAF protection.

The issues are summarized in the following sections, but full PoCs and information about the types of rules vulnerable to evasion will be omitted.

ModSecurity Parser Activation

ModSecurity includes built in parsers for request bodies of four types: x-www-form-urlencoded, multipart/form-data, JSON, and XML. At most, for any individual HTTP request, one of those four parsers will be active for the request.

The mechanism to activate either the JSON parser or the XML parser is an ordinary ModSecurity rule that includes the relevant action (e.g. ctl:requestBodyProcessor=XML). As such, the conditions under which each of those parsers may be activated is controlled by the administrator.

The ModSecurity project includes a file called ‘modsecurity.conf-recommended’ that includes a small number of basic rules and other configuration items that are typically desirable. Among these are rules for parser activation as described in the previous paragraph.

The core of the problem is that rules 200000 and 200001 each use a regular expression that is imprecise. A specially crafted Content-Type request header could be composed that would result in the incorrect body parser being activated. Having the incorrect parser active within ModSecurity can result in at least some malicious content bypassing rules which ordinarily would have detected it.

Also provided in the same file is a sample, commented-out rule (200006) that will engage the JSON parser for additional Content-Type values. Subsequent analysis by the ModSecurity team found that it suffered from a slightly different – but still comparable – weakness.

Each of the rules discussed here has been amended to make its regular expression more precise in what it will match. Users are advised to incorporate these changes into their installation’s configuration at the earliest opportunity.

Parsing of multipart/form-data

Two of the issues that were identified involve problems with how the ModSecurity engine parses the content of a request body of type multipart/form-data.

In both cases, a malicious actor could compose specially crafted input that could result in ModSecurity populating its argument collections with strings that are different from what the web server would see. This mismatch can result in some ModSecurity rules failing to detect content that it normally would have detected.

While one of these two issues is only known to be a problem when certain types of web servers are being protected (Apache Tomcat has been confirmed to be affected while neither Apache HTTP Server nor nginx appear to be), the second of the two is of more widespread potential impact.

The fixes in the ModSecurity engine for both issues involve additional use cases setting the MULTIPART_STRICT_ERROR variable. This variable is inspected by rule 200003 in ‘modsecurity.conf-recommended’. Users are advised to ensure that they have this rule, or an equivalent, in place in their installations.


The bug bounty hunter has recently posted a blog that contains additional information about the topics discussed here. It can be found at: https://terjanq.medium.com/waf-bypasses-via-0days-d4ef1f212ec