Skip to content

Commit

Permalink
Updating tests and filtering logic with better regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sifex committed Feb 16, 2025
1 parent 714d073 commit d9f4d8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sigma/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def apply_on_rule(

# Replace each instance of the original condition name with the new condition name to avoid conflicts
filter_condition = re.sub(
rf"(^|\s|\()+{original_cond_name}(\s|$|\))+",
cond_name,
rf"(\s|\(|^){original_cond_name}(\s|$|\))",
r"\1" + cond_name + r"\2",
filter_condition,
)
rule.detection.detections[cond_name] = condition
Expand Down
18 changes: 18 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,21 @@ def test_regression_github_issue_321_brackets(
assert test_backend.convert(rule_collection) == [
'(EventID=4625 or EventID2=4624) and not User startswith "adm_"'
]


def test_regression_github_issue_321_selection_confusion(rule_collection, test_backend, sigma_filter):
sigma_filter.filter = SigmaGlobalFilter.from_dict(
{
"rules": [
"6f3e2987-db24-4c78-a860-b4f4095a7095",
],
"filter": {"User|startswith": "adm_"},
"condition": "not selection",
}
)

rule_collection.rules += [sigma_filter]

assert test_backend.convert(rule_collection) == [
'(EventID=4625 or EventID2=4624) and not User startswith "adm_"'
]

0 comments on commit d9f4d8c

Please sign in to comment.