Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removes multiline from default regex modifiers [breaking] #876

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

M4tteoP
Copy link
Member

@M4tteoP M4tteoP commented Sep 18, 2023

This PR evaluates the needed changes to align Coraza to Modsec v2 behavior rather than Modsec v3 in terms of default modifiers when compiling regexes. This necessity has been raised by coreruleset/coreruleset#3277.

We are currently running with two default modifiers:

  • s (dotall)
  • m (multiline mode)

While Modsec v2 (the reference implementation for the CRS) has:

  • PCRE2_DOTALL
  • PCRE2_DOLLAR_ENDONLY

Running the CRS rules with multiline may lead to false positives and lower performance.

Opening the PR to further discuss this, and whether we accept a breaking change for v3.* or not.

// The so called DOLLAR_ENDONLY modifier in PCRE2 is meant to tweak the meaning of dollar '$'
// so that it matches only at the very end of the string (see: https://www.pcre.org/current/doc/html/pcre2pattern.html#SEC6)
// It seems that re2 already behaves like that by default.
pattern: `123$`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to find the DOLLAR_ENDONLY modifier for RE2, but it seems that re2 by default behaves like DOLLAR_ENDONLY enabled.
See also https://regex101.com/r/mUcy69/1 (Mind the regex option D (dollar end only) enabled).
Am I missing something?

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.10%. Comparing base (4ff1f76) to head (30f1c6b).
Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #876      +/-   ##
==========================================
+ Coverage   82.72%   83.10%   +0.38%     
==========================================
  Files         162      164       +2     
  Lines        9080     7673    -1407     
==========================================
- Hits         7511     6377    -1134     
+ Misses       1319     1041     -278     
- Partials      250      255       +5     
Flag Coverage Δ
default 83.10% <100.00%> (+5.27%) ⬆️
examples 83.10% <100.00%> (+56.67%) ⬆️
ftw 83.10% <100.00%> (+35.74%) ⬆️
ftw-multiphase 83.10% <100.00%> (+33.56%) ⬆️
tinygo 83.10% <100.00%> (+7.70%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anuraaga
Copy link
Contributor

Good to see ftw passing with this change. I wouldn't merge it until seeing the PR to ModSec v3 doing the same, otherwise someone will just ask in the future why we aren't aligned with ModSec v3.

@jptosso jptosso mentioned this pull request Dec 19, 2023
16 tasks
@jcchavezs
Copy link
Member

Maybe it is a good idea to coordinate this in @M4tteoP @airween

@M4tteoP
Copy link
Member Author

M4tteoP commented Feb 8, 2024

Totally 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants