Skip to content

multimatch applies operator too often #1086

@dstelter

Description

@dstelter

Consider this rule:

SecRule ARGS:c ".*" "id:4,multimatch,t:none,t:lowercase,t:lowercase,t:lowercase,msg:%{matched_var}"

Intuitively, this rule should never invoke the operator more than twice, right?

My test cases look like this:

{
    "request": "/?c=test",
    "comment": "Only initial apply",
    "matches": [
        {"id": 4, "msg": "test"}
    ]
},
{
    "request": "/?c=Test",
    "comment": "Initial apply and after first lowercase transform",
    "matches": [
        {"id": 4, "msg": "Test"},
        {"id": 4, "msg": "test"}
    ]
}

The first test is successful, but the second request yields these matches ("(id, msg)"):

('4', 'Test'), ('4', 'test'), ('4', 'test')

The operator is applied once too often if there are more multiple transforms and any of them modify the input. This problem only occurs if multiple transforms are present. The operator is always applied with the final transform value.

Another case:

Rule:

SecRule ARGS:b ".*" "id:3,multimatch,t:none,t:lowercase,t:hexEncode,t:length,t:removeNulls,msg:%{matched_var}"

Test:

{
    "request": "/?b=Test",
    "matches": [
        {"id": 3, "msg": "Test"},
        {"id": 3, "msg": "test"},
        {"id": 3, "msg": "74657374"},
        {"id": 3, "msg": "8"}
    ]
}

Reported matches:

('3', 'Test'), ('3', 'test'), ('3', '74657374'), ('3', '8'), ('3', '8')

Removing the removeNulls transform makes the duplicate match disappear, but it shouldn't appear at all if removeNulls doesn't modify the input.

Am I misinterpreting the multimatch specification or is there a bug?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions