Skip to content

fix(rule): validate types of level, tags and related meta fields - #527

Open
nkbeast wants to merge 2 commits into
SigmaHQ:mainfrom
nkbeast:fix/rule-meta-field-type-validation
Open

fix(rule): validate types of level, tags and related meta fields#527
nkbeast wants to merge 2 commits into
SigmaHQ:mainfrom
nkbeast:fix/rule-meta-field-type-validation

Conversation

@nkbeast

@nkbeast nkbeast commented Aug 11, 2026

Copy link
Copy Markdown

What changed

Rule meta fields with unexpected YAML types crashed parsing with an unhandled AttributeError instead of producing a proper SigmaError validation error:

  • level: 123AttributeError: '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)

status already had an isinstance(str) guard; level, tags and related did not, so malformed rules bypassed the collect_errors machinery and crashed callers (e.g. sigma-cli batch rule checks) with a raw exception instead of a per-rule validation error. All three now emit SigmaLevelError / SigmaTagError / SigmaRelatedError, collected or raised like every other rule error.

How verified

  • Added tests: malformed level, tags, related are collected as the expected error classes with collect_errors=True, and raised as SigmaLevelError without it.
  • pytest: 1524 passed (2 pre-existing failures in tests/test_plugins.py are subprocess install tests unrelated to this change).
  • black --check . and mypy: clean.

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.
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.

1 participant