Skip to content
Open
Changes from all commits
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
4 changes: 2 additions & 2 deletions apache2/re.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@
* It breaks up the input string into name-parameter pairs and places
* them into the given table.
*/
int msre_parse_generic(apr_pool_t *mp, const char *text, apr_table_t *vartable,

Check failure on line 994 in apache2/re.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 60 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZ0BoFYTZK90Cyi09ps3&open=AZ0BoFYTZK90Cyi09ps3&pullRequest=3519
char **error_msg)
{
char *p = (char *)text;
Expand Down Expand Up @@ -1075,13 +1075,13 @@
return -1;
} else
if (*p == '\\') {
if ( (*(p + 1) == '\0') || ((*(p + 1) != '\'')&&(*(p + 1) != '\\')) ) {
if ((*(p + 1) == '\0')) {
*error_msg = apr_psprintf(mp, "Invalid quoted pair at position %d: %s",
(int)(p - text), text);
free(value);
return -1;
}
p++;
if ((*(p + 1) == '\'') || (*(p + 1) == '\\')) p++; // compatibility with previous behaviour
*(d++) = *(p++);
Comment on lines 1077 to 1085
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

This change is in msre_parse_generic() (used for both target and action parsing), so it relaxes backslash handling for all quoted parameters—not just setvar. If the intent is setvar-only, consider moving this logic into the setvar parser; otherwise please update the PR title/description to reflect the broader behavioral change.

Copilot uses AI. Check for mistakes.
Comment on lines +1078 to 1085
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

There are regression tests covering setvar actions, but none appear to cover the newly-allowed case of a single backslash inside a quoted parameter (e.g. a Windows-style path like C:\temp written with single backslashes in the config). Please add a regression test that exercises a quoted action parameter containing an unescaped backslash to lock in this behavior and prevent accidental re-tightening of the parser.

Copilot uses AI. Check for mistakes.
} else
if (*p == '\'') {
Expand Down
Loading