fix(rule): validate types of level, tags and related meta fields - #527
Open
nkbeast wants to merge 2 commits into
Open
fix(rule): validate types of level, tags and related meta fields#527nkbeast wants to merge 2 commits into
nkbeast wants to merge 2 commits into
Conversation
Rule meta fields with unexpected YAML types crashed parsing with an unhandled AttributeError instead of a proper SigmaError validation error: * level: 123 -> AttributeError: 'int' object has no attribute 'upper' * tags: [123] -> AttributeError: 'int' object has no attribute 'split' * related: [foo] -> AttributeError: 'str' object has no attribute 'keys' The status field already had an isinstance check; level, tags and related items did not, so malformed rules bypassed the collect_errors machinery and blew up callers (e.g. sigma-cli batch checks) with a raw exception. All three now produce SigmaLevelError / SigmaTagError / SigmaRelatedError, collected or raised like every other rule error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Rule meta fields with unexpected YAML types crashed parsing with an unhandled
AttributeErrorinstead of producing a properSigmaErrorvalidation error:level: 123→AttributeError: 'int' object has no attribute 'upper'(sigma/rule/base.py)tags: [123]→AttributeError: 'int' object has no attribute 'split'(sigma/rule/base.py)related: [foo]→AttributeError: 'str' object has no attribute 'keys'(sigma/rule/attributes.py)statusalready had anisinstance(str)guard;level,tagsandrelateddid not, so malformed rules bypassed thecollect_errorsmachinery and crashed callers (e.g. sigma-cli batch rule checks) with a raw exception instead of a per-rule validation error. All three now emitSigmaLevelError/SigmaTagError/SigmaRelatedError, collected or raised like every other rule error.How verified
level,tags,relatedare collected as the expected error classes withcollect_errors=True, and raised asSigmaLevelErrorwithout it.pytest: 1524 passed (2 pre-existing failures intests/test_plugins.pyare subprocess install tests unrelated to this change).black --check .andmypy: clean.