owasp-modsecurity / owasp-modsecurity/ModSecurity

Behavior change in regex macro expansion from 2.9.7 to 2.9.8 affecting CRS 3.2.x and 3.3.x

Open
#3,380 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

2.x
Dominant language
C++
Stars
9.8k
Forks
1.8k
Avg merge
2h 46m
Merged PRs (30d)
1

Description

Describe the bug

The way macros are expanded to regex patterns in rules changed from ModSecurity 2.9.7 to 2.9.8.

This affects CRS 3.2.x (920420, 920480) and CRS 3.3.x (920480) that both use the feature. CRS 4.x no longer uses this features and is thus not affected.

Logs and dumps

ModSecurity 2.9.7 debug log

... Resolved macro %{tx.allowed_request_content_type} to: application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/soap+xml|application/x-amf|application/json|application/octet-stream|application/csp-report|application/xss-auditor-report|text/plain
... Escaping pattern [^application\/x-www-form-urlencoded|multipart\/form-data|text\/xml|application\/xml|application\/soap\+xml|application\/x-amf|application\/json|application\/octet-stream|application\/csp-report|application\/xss-auditor-report|text\/plain$]
... 
... Rule returned 0.
... No match, not chained -> mode NEXT_RULE.
...

ModSecurity 2.9.8 debug log

... Resolved macro %{tx.allowed_request_content_type} to: application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/soap+xml|application/x-amf|application/json|application/octet-stream|application/csp-report|application/xss-auditor-report|text/plain
... Expanded-macro pattern [^application\/x-www-form-urlencoded|multipart\/form-data|text\/xml|application\/xml|application\/soap\+xml|application\/x-amf|application\/json|application\/octet-stream|application\/csp-report|application\/xss-auditor-report|text\/plain$]
...
... Set variable "tx.anomaly_score_pl1" to "5".
... 

To Reproduce

$ curl -H "Content-Type: application/soap+xml" -d "@example.xml" -v http://localhost

The content type application/soap+xml is in the list of allowed content-types for CRS 3.2.3 by default. With ModSecurity 2.9.8 it is suddenly no longer accepted and rule 920420 PL1 Request content type is not allowed by policy is being triggered by this Content-Type.

Expected behavior

Regex macro expansion behavior is the same between 2.9.7 and 2.9.8. The curl call above should not trigger CRS 920420 in version 3.2.3.

Server (please complete the following information):

  • ModSecurity version (and connector): ModSecurity 2.9.8
  • WebServer: Apache 2.4.63
  • OS (and distro): Ubuntu

Rule Set (please complete the following information):

  • CRS 3.2.x, CRS 3.3.x

Additional context

PR #2357 might be a candidate for the introduction of this bug.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing PR #2357 and the regex macro expansion path, then reproduce the issue with the provided curl request against CRS rule 920420. Compare the 2.9.7 and 2.9.8 debug-log behavior; done means application/soap+xml is accepted as in 2.9.7 without triggering the rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
apache, cpp
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.