Skip to content

Conversation

@sifex
Copy link
Collaborator

@sifex sifex commented Dec 12, 2025

Context

Reference:
SigmaHQ/sigma-specification#133

This pull request enhances the flexibility and correctness of Sigma filter rule handling, particularly around the rules field in filters. The changes allow the rules field to explicitly accept the special value "any" or an empty list to indicate the filter should apply to all rules matching the logsource, and ensure robust error handling when the field is missing. The update also adds comprehensive tests for these scenarios, improving overall reliability.

Sigma filter rule handling improvements:

  • The SigmaGlobalFilter.rules field now accepts either a list of rule references or the string "any", allowing filters to target all rules matching the logsource when "any" or an empty list is provided. [1] [2] [3]
  • The logic for applying filters has been updated so that filters with rules: "any" (or an empty list) apply to all rules with a matching logsource, and never to correlation rules. [1] [2]

Error handling and validation:

  • If the rules field is missing from a filter, a clear error is now raised, instructing users to specify "any" or a specific rule reference. [1] [2]

Testing enhancements:

  • Extensive new tests have been added to cover scenarios including: filters with rules: "any", partial logsource matching, more specific logsource filters, exclusion of correlation rules, empty rules lists, and missing rules fields. [1] [2]

Type safety improvements:

  • Type checking and casting in the modifier logic have been made more robust by generalizing the type_check method and ensuring correct casting in the apply method. [1] [2]

sifex and others added 5 commits December 12, 2025 11:21
The rules field in Sigma Filters is now optional. When not specified,
filters will apply to all rules that match the logsource criteria,
rather than requiring explicit rule IDs or titles.

Changes:
- Modified SigmaGlobalFilter.from_dict() to set rules to empty list when not specified
- Updated SigmaFilter._should_apply_on_rule() to apply filters to all matching rules when rules field is empty
- Updated test_no_rules_section to verify filters now apply when rules is None
- Added test_filter_without_rules_field_applies_to_all_matching_logsource to verify global filter behavior
- Removed validation errors for missing rules field from parametrized tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request makes the rules field optional in Sigma filters, enabling filters to apply to all rules with matching logsource when the rules field is not specified. Previously, omitting the rules field would raise a SigmaFilterRuleReferenceError.

Key changes:

  • Modified filter logic to treat missing or empty rules field as "apply to all rules with matching logsource"
  • Updated _should_apply_on_rule method to implement logsource-based matching when no specific rules are listed
  • Added comprehensive test coverage for the new optional rules behavior including edge cases
  • Removed validation error tests for missing rules field since it's now valid

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/test_filters.py Removed SigmaFilterRuleReferenceError import, updated test_no_rules_section to verify filter application, added 5 new comprehensive tests for optional rules field behavior including logsource matching variations and correlation rule exclusion, removed validation error test cases for missing/None rules field
sigma/filters.py Modified SigmaGlobalFilter.from_dict to return empty list instead of raising error when rules field is missing, refactored _should_apply_on_rule to check correlation rules first, then logsource matching, and return True for logsource matches when no rules specified
sigma/modifiers.py Changed type_check parameter from Type[T] to Type[Any] for flexibility, added cast(list[T], r) when returning list from modify method (appears unrelated to main PR purpose)
poetry.lock Auto-generated dependency updates for development tools (black 25.11.0→25.12.0, coverage 7.12.0→7.13.0, pytest 9.0.1→9.0.2, mypy 1.18.2→1.19.0, and other dev dependencies)

@sifex sifex changed the title Make rules field optional in Sigma Filters [v1] Support all and any for Sigma Filters Dec 12, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@sifex sifex changed the title [v1] Support all and any for Sigma Filters [v1] Support any for Sigma Filters rule references Dec 13, 2025
@sifex sifex requested a review from Copilot December 13, 2025 15:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

@thomaspatzke thomaspatzke merged commit 65067f2 into main Dec 14, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants