fix: avoid UnboundLocalError in SigmaCorrelationRule.from_dict with collect_errors=True - #545
Open
cristianchiriac wants to merge 4 commits into
Conversation
…ollect_errors=True When an extended (string) condition is used with a non-temporal correlation type, or condition parsing otherwise fails, and collect_errors=True, 'condition' was never assigned, so cls() raised an UnboundLocalError instead of returning the collected errors.
…Rule.from_dict
A non-dict 'correlation' value (None, string, int, list, ...) made
.get("type") raise an unhandled AttributeError, bypassing
collect_errors entirely. Validate the type up front and record it as
a SigmaCorrelationRuleError instead.
thomaspatzke
approved these changes
Sep 19, 2026
Member
|
Please reformat with |
Contributor
Author
|
Thanks for flagging this. I ran black 26.5.1 (the version pinned in the pre-commit config) on |
thomaspatzke
approved these changes
Sep 20, 2026
Member
|
Now there are mypy type validation issues. |
Contributor
Author
|
Fixed in ee2d3ad. The new |
This branch has not been deployed
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.
Summary
Two related crashes in
SigmaCorrelationRule.from_dict(..., collect_errors=True), which is meant to collect parsing errors into.errorsinstead of raising:1.
conditionUnboundLocalError. When an extended (string)conditionis used with a non-temporal correlation type — or condition parsing otherwise fails — the local variableconditionis never assigned before being passed tocls(...):2. Non-dict
correlationfield. A non-dictcorrelationvalue (None, a string, an int, a list, ...) makes.get("type")raise an unhandledAttributeError, bypassingcollect_errorsentirely:Fix
conditionto the same default already used for the dataclass field (SigmaCorrelationCondition(GTE, 1)) before the branch that parses it, so the object can still be constructed on thecollect_errors=Truepath while the real error is recorded in.errors.correlationis a dict up front; if not, record aSigmaCorrelationRuleError(raising it immediately whencollect_errors=False, matching the rest of the function) and fall back to an empty dict so the remaining field-level checks still run and report every problem at once.Test plan
tests/test_correlations.pyfor both cases (raising andcollect_errors=Truepaths).pytest tests/test_filters.py tests/test_correlations.pypasses (125 passed, 1 skipped).test_plugins.py).