Repository navigation
Add validator for tautological contains/startswith/endswith values - #617
aditya226-sharma wants to merge 2 commits into
Conversation
Values that are empty or reduce to a single path separator match (almost) every value. This is easy to miss when escape sequences collapse, e.g. a value written as '\\' is parsed as one literal backslash, so a contains list with '\Users\' and '\\' matches every path. Detection items with the all modifier are skipped because all values have to match and a single tautological value does not turn the whole item into a tautology.
|
Thanks for picking this up so quickly, and for running it over the rule set. I checked it against the original case from #615: with this branch the validator flags the One note on my own suggestion, which your numbers seem to support: for |
A lone `\` or `/` with `contains` matches any value containing that separator, which is effectively every value for path-like fields. With `startswith` and `endswith` the same value only anchors the match at one end of the value, so it remains selective and is not a tautology. Only report a single separator when the `contains` modifier is present. Empty values are still reported for all three modifiers, where the modifier adds a bare `*` and the value matches everything. Update the issue description, validator docstring and rule-validation docs to match. The tests now parametrize the single-separator cases over `contains` only, cover empty values for all three modifiers, and list `startswith`/`endswith` lone separators as explicit non-issues.
|
Thanks — agreed, and the corpus numbers back it up. I've limited the single-separator check to The distinction is in the compiled pattern: Changes:
Severity stays Re-ran over Local checks: |
|
Thanks, this looks right to me. I agree a separate LOW validator for startswith/endswith isn't needed; those values are selective, so it would just be noise. Re-checked the updated branch: the #615 case is still flagged and the tautological tests pass (18/18). |
Summary
Adds
TautologicalValueValidator(tautological_value), as suggested in #615. It reportscontains,startswithandendswithvalues that are empty, andcontainsvalues that reduce to a single path separator (\or/), because such values match (almost) every value of a field.The validator is registered automatically through the existing
sigma.validators.corediscovery, lives next toDoubleWildcardValidator/EscapedWildcardValidatorinsigma/validators/core/values.py, and is documented indocs/guides/rule_validation.rst.Why values, not only strings
SigmaStringparses escape sequences, so the YAML value'\\'(two literal backslashes) becomes a single backslash. A list such astherefore compiles to
... LIKE '%\Users\%' OR ... LIKE '%\%', and the second branch matches every Windows path. The whole detection item becomes a tautology even though the rule looks like it has two conditions. The validator inspectsSigmaDetectionItem.original_valuewhere available, since the modifiers add the wildcards forcontains/startswith/endswithtovalue.Scope
Reported:
|contains: '',|startswith: '',|endswith: '') — the modifier turns them into a bare*;\or one/with thecontainsmodifier —*\*matches every value containing a separator.Not reported:
startswith/endswith—\*and*\only anchor the match at one end of the value, so they stay selective and are not tautologies;|allmodifier. All values have to match there, so a single tautological value is redundant but does not make the detection item a tautology. This also avoids flagging the intentionalpath|contains|allrules in the current rule set;Severity is
MEDIUM, consistent with "the meaning of the rule can be different from intended".Impact on the SigmaHQ rule set
I ran the validator over
SigmaHQ/sigmaat53b90df(3305 rules inrules/andrules-threat-hunting/, all parsed successfully). It reports 2 detection items:rules/windows/process_creation/proc_creation_win_susp_image_missing.ymlImage|contains: '\\'rules-threat-hunting/windows/process_creation/proc_creation_win_powershell_susp_child_processes.ymlCommandLine|contains: ['qfe list', ..., '']wmicfilter match everyCommandLine, so the other values are dead (tracked in SigmaHQ/sigma#6596)The earlier version of this validator also flagged two
FileName|startswith: '\\'rules from the same corpus; that check is now limited tocontains.For comparison, the existing validators report 56
EscapedWildcardIssue, 8NumberAsStringIssue, 4SpecificInsteadOfGenericLogsourceIssueand 1InvalidATTACKTagIssueon the same corpus, so this is in line with the current signal level.I have not touched the rule repository; the table is data for the maintainers to decide whether the flagged rules should be fixed or excluded.
Tests
tests/test_validators.pycovers the reported repro, empty values for all three modifiers, a lone separator withcontains, and the non-flagged cases (path values, UNC paths, wildcards, unrelated modifiers,|all, correlation rules, and lone separators withstartswith/endswith).Local checks:
pytest:1964 passed, 1 skippedblack --check: cleanmypy -p sigma: cleanDisclosure
I used an AI assistant to help analyze the issue, write the implementation and tests, and measure the impact on the rule set. The code, test results and rule-set numbers above were verified locally against
mainate522188.