Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ Windows build information can be found [here](build/win32/README.md).
* **Default:** PCRE2 is detected and used.
* **Fallback:** legacy PCRE can be used if `--with-pcre` is explicitly provided (`WITH_PCRE`).
* In other words, current builds expect PCRE2 unless explicitly configured otherwise.
* `@rx` and `@rxGlobal` compile patterns with `DOTALL | MULTILINE` by default. Pass
`--enable-regex-dollar-endonly=yes` to compile them with `DOTALL | DOLLAR_ENDONLY`
instead, matching ModSecurity v2's `@rx` behavior (`^`/`$` anchor only at the
start/end of the whole subject, not at internal line breaks). This flag is
disabled by default; see [issue #3295](https://github.com/owasp-modsecurity/ModSecurity/issues/3295).
Comment thread
fzipi marked this conversation as resolved.
Outdated

All other dependencies are related to operators specified within SecRules or configuration directives and may not be required for compilation.

Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ MSC_ARG_ENABLE_BOOL([afl-fuzz], [Turn on the afl fuzzer compilation utilities],
MSC_ARG_ENABLE_BOOL([examples], [Turn on the examples compilation (default option)], [true], [buildExamples])
MSC_ARG_ENABLE_BOOL([parser-generation], [Enables parser generation during the build], [false], [buildParser])
MSC_ARG_ENABLE_BOOL([mutex-on-pm], [Treat pm operations as critical section], [false], [mutexPm])
MSC_ARG_ENABLE_BOOL([regex-dollar-endonly], [Compile @rx/@rxGlobal patterns with PCRE(2)_DOLLAR_ENDONLY instead of PCRE(2)_MULTILINE, matching ModSecurity v2 behavior (see issue #3295)], [false], [regexDollarEndonly])
if test "$regexDollarEndonly" = "true"; then
MODSEC_REGEX_DOLLAR_ENDONLY_CPPFLAGS="-DMODSEC_REGEX_DOLLAR_ENDONLY=1"
GLOBAL_CPPFLAGS="$GLOBAL_CPPFLAGS $MODSEC_REGEX_DOLLAR_ENDONLY_CPPFLAGS"
fi


if test $buildParser = true; then
Expand Down
9 changes: 7 additions & 2 deletions src/operators/rx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
namespace modsecurity {
namespace operators {

#ifdef MODSEC_REGEX_DOLLAR_ENDONLY
static const bool kRxMultiLine = false;
#else
static const bool kRxMultiLine = true;
#endif

bool Rx::init(const std::string &arg, std::string *error) {
if (m_string->m_containsMacro == false) {
m_re = new Regex(m_param);
m_re = new Regex(m_param, false, kRxMultiLine);

Check failure on line 37 in src/operators/rx.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ94cWHrLJyjbmyNok0k&open=AZ94cWHrLJyjbmyNok0k&pullRequest=3600
}

return true;
Expand All @@ -46,7 +51,7 @@

if (m_string->m_containsMacro) {
std::string eparam(m_string->evaluate(transaction));
re = new Regex(eparam);
re = new Regex(eparam, false, kRxMultiLine);

Check failure on line 54 in src/operators/rx.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ94cWHrLJyjbmyNok0l&open=AZ94cWHrLJyjbmyNok0l&pullRequest=3600
} else {
re = m_re;
}
Expand Down
9 changes: 7 additions & 2 deletions src/operators/rx_global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
namespace modsecurity {
namespace operators {

#ifdef MODSEC_REGEX_DOLLAR_ENDONLY
static const bool kRxGlobalMultiLine = false;
#else
static const bool kRxGlobalMultiLine = true;
#endif

bool RxGlobal::init(const std::string &arg, std::string *error) {
if (m_string->m_containsMacro == false) {
m_re = new Regex(m_param);
m_re = new Regex(m_param, false, kRxGlobalMultiLine);

Check failure on line 37 in src/operators/rx_global.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ94cWBTLJyjbmyNok0i&open=AZ94cWBTLJyjbmyNok0i&pullRequest=3600
}

return true;
Expand All @@ -46,7 +51,7 @@

if (m_string->m_containsMacro) {
std::string eparam(m_string->evaluate(transaction));
re = new Regex(eparam);
re = new Regex(eparam, false, kRxGlobalMultiLine);

Check failure on line 54 in src/operators/rx_global.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ94cWBTLJyjbmyNok0j&open=AZ94cWBTLJyjbmyNok0j&pullRequest=3600
} else {
re = m_re;
}
Expand Down
7 changes: 4 additions & 3 deletions src/utils/regex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ bool crlfIsNewline() {
return crlf_is_newline;
}

Regex::Regex(const std::string& pattern_, bool ignoreCase)
Regex::Regex(const std::string& pattern_, bool ignoreCase, bool multiLine)
: pattern(pattern_.empty() ? ".*" : pattern_) {
#ifndef WITH_PCRE
PCRE2_SPTR pcre2_pattern = reinterpret_cast<PCRE2_SPTR>(pattern.c_str());
uint32_t pcre2_options = (PCRE2_DOTALL|PCRE2_MULTILINE);
uint32_t pcre2_options = PCRE2_DOTALL |
(multiLine ? PCRE2_MULTILINE : PCRE2_DOLLAR_ENDONLY);
if (ignoreCase) {
pcre2_options |= PCRE2_CASELESS;
Comment thread
fzipi marked this conversation as resolved.
}
Expand All @@ -103,7 +104,7 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
#else
const char *errptr = nullptr;
int erroffset;
int flags = (PCRE_DOTALL|PCRE_MULTILINE);
int flags = PCRE_DOTALL | (multiLine ? PCRE_MULTILINE : PCRE_DOLLAR_ENDONLY);

if (ignoreCase == true) {
flags |= PCRE_CASELESS;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ struct SMatchCapture {

class Regex {
public:
explicit Regex(const std::string& pattern_, bool ignoreCase = false);
explicit Regex(const std::string& pattern_, bool ignoreCase = false,
bool multiLine = true);
~Regex();

// m_pc and m_pce can't be easily copied
Expand Down
Loading