diff --git a/src/secrules_parsing/model/secrules.tx b/src/secrules_parsing/model/secrules.tx index 14a0cda..f1fb49a 100644 --- a/src/secrules_parsing/model/secrules.tx +++ b/src/secrules_parsing/model/secrules.tx @@ -99,7 +99,7 @@ Operator: 'gsbLookup' gsblookup=INT | 'gt' gt=Macro | 'inspectFile' inspectfile=URI | 'ipMatch' ipmatch+=IPCIDR[','] | 'ipMatchF' ipmatchf=STRING | 'ipMatchFromFile' ipmatchfromfile=STRING | 'le' le=INT | 'lt' lt=Macro | nomatch ?= 'noMatch' | 'pmf' pmf=StringWithSpacesOrPath | 'pmFromFile' pmfromfile=StringWithSpacesOrPath | 'pm' pm=PatternMatch | - 'rbl' rbl=Hostname | 'rsub' rsub=AnythingBetweenSlashes | 'rx' rx=RegExp | 'streq' streq=StringWithMacros | + 'rbl' rbl=Hostname | 'rsub' rsub=AnythingBetweenSlashes | 'rx' rx=RegExp | 'streq' streq=PatternMatch | 'strmatch' strnmatch=STRING | unconditionalmatch ?= 'unconditionalMatch' | 'validateByteRange' validatebyterange=ByteRangeList | 'validateDTD' validatedtd=PathNameValue | 'validateHash' validatehash=RegExp | 'validateSchema' validateschema=PathNameValue | @@ -183,8 +183,6 @@ IPCIDR: /[0-9a-f\.\:]*:[0-9a-f\.\:]*(?:\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9]))?|[0 // Single Quote delimited STRING SQDelimitedSTRING: "'" msg=MessageValue? ':'? macro=MacroVar? "'"; -// This string has macros inside, but their value isn't stored in a variable for now. -StringWithMacros: "'" ExtendedMacroWithComma "'"; // String with spaces: when using streq, there are places where a request line is tested StringWithSpaces: /[A-Za-z0-9\-\/\ \._]+/; diff --git a/tests/test_operators.py b/tests/test_operators.py index bdd58a8..2aa7525 100644 --- a/tests/test_operators.py +++ b/tests/test_operators.py @@ -6,6 +6,8 @@ Note: Some operators may have parsing issues or may require specific syntax. Tests are designed to validate the current parser behavior. """ +import pytest + from secrules_parsing import parser @@ -118,6 +120,36 @@ def test_operator_streq() -> None: assert matches == 1 +# Regression for issue #163: these were silently parsed as an implicit @rx +STREQ_VALUES = [ + "POST", + "'POST'", + "phpinfo()", + "'phpinfo()'", + "a[b]", + "'a[b]'", + "'a{b}'", + "%{tx.a}()", + "'%{tx.a}()'", + "HTTP/1.1", + "GET /index.html HTTP/1.1", +] + + +@pytest.mark.parametrize("value", STREQ_VALUES) +def test_operator_streq_values(value: str) -> None: + """@streq keeps its value, quoted or not, with brackets and macros""" + rule_text = f""" + SecRule ARGS "@streq {value}" \\ + "id:1006,phase:2,deny" + """ + parsed_rule = parser.process_from_str(rule_text) + assert not isinstance(parsed_rule, dict), parsed_rule + operator = parsed_rule.rules[0].operator + assert operator.streq == value + assert not operator.rx + + def test_operator_strmatch() -> None: """Test @strmatch operator - Note: may have parsing issues""" rule_text = """