The current behavior with invalid macros is also kinda surprising: the invalid macro is just dropped from the rule.
This means that a rule like SecRule ARGS:id "@contains %{" "id:1, phase:1,deny, status:403,msg:'foobar',log,auditlog" will actually end up being a @contains with an empty value (but weirdly enough %{ will be logged as the operator data in the debug logs), and will match on everything, which shouldn't be possible as @contains requires an argument (this is technically a different problem, let me know if you want to track this in a separate issue).
If an invalid macro is encountered, it would probably be best to just leave it as it (and log a warning/error to the user)
Description
Coraza crashes if a rule use some (most ?) operators (
@contains
for example) and it ends with a%
due to a bug in the macro expansion code.It seems that everything that calls
macro.NewMacro
is impacted (so operators,msg
field, ...).Steps to reproduce
The last rule gives this stacktrace (using the example
http-server
from the repo):Expected result
Not crashing :)
The current behavior with invalid macros is also kinda surprising: the invalid macro is just dropped from the rule. This means that a rule like
SecRule ARGS:id "@contains %{" "id:1, phase:1,deny, status:403,msg:'foobar',log,auditlog"
will actually end up being a@contains
with an empty value (but weirdly enough%{
will be logged as the operator data in the debug logs), and will match on everything, which shouldn't be possible as@contains
requires an argument (this is technically a different problem, let me know if you want to track this in a separate issue).If an invalid macro is encountered, it would probably be best to just leave it as it (and log a warning/error to the user)