-
-
Notifications
You must be signed in to change notification settings - Fork 130
[v1] Support any for Sigma Filters rule references
#430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
There was a problem hiding this 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
rulesfield as "apply to all rules with matching logsource" - Updated
_should_apply_on_rulemethod 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
rulesfield 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) |
all and any for Sigma Filters
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nto feature/optional-filter-rules
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nto feature/optional-filter-rules
There was a problem hiding this 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.
There was a problem hiding this 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.
…messages accordingly
all and any for Sigma Filtersany for Sigma Filters rule references
There was a problem hiding this 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.
Context
Reference:
SigmaHQ/sigma-specification#133
This pull request enhances the flexibility and correctness of Sigma filter rule handling, particularly around the
rulesfield in filters. The changes allow therulesfield 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:
SigmaGlobalFilter.rulesfield 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]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:
rulesfield 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:
rules: "any", partial logsource matching, more specific logsource filters, exclusion of correlation rules, empty rules lists, and missingrulesfields. [1] [2]Type safety improvements:
type_checkmethod and ensuring correct casting in theapplymethod. [1] [2]