[high] Re-apply #99: report collection errors and broken filters in sigma check (reverted with #105) - #109
Open
elhoim wants to merge 1 commit into
Open
[high] Re-apply #99: report collection errors and broken filters in sigma check (reverted with #105)#109elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
load_and_check_rules() only looked at the errors of the rules in SigmaCollection.rules. Errors that are not attached to a rule, such as an unknown collection 'action:' or an invalid filter (filters are kept in SigmaCollection.filters), were never reported, so 'sigma check' passed inputs that 'sigma convert' rejects. These errors are now reported, counted as rule errors (so --fail-on-error applies) and added to the JUnit report. Rule errors are also contained in SigmaCollection.errors; they are skipped there so they are not counted twice. Re-applies SigmaHQ#99 (cherry picked from commit 0d0231f), which was merged but then undone on main: the merge of SigmaHQ#105 (8effb4c) brought in cdd5436, a revert of a conflict-resolution merge (86d3041) that had carried SigmaHQ#98 and SigmaHQ#99 into the SigmaHQ#105 branch. SigmaHQ#99 did not conflict with SigmaHQ#105; it was only caught by that revert. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
BLUF
sigma check"). It was merged, but the revertcdd5436that came in with [high] Write finalized, postprocessed queries with --output-dir #105 (merge8effb4c) silently removed it frommain.sigma check --fail-on-errorpasses (exit 0, "Found 0 errors") on files thatsigma convertrejects - unknown collectionaction:and invalid filters are never reported.0d0231fonto currentmain; [high] Write finalized, postprocessed queries with --output-dir #105 did not touchcheck.py, so there was no conflict.mainand pass here. Full suite with thepoetry.lockpins (pySigma 1.4.0, click 8.4.2, pyparsing 3.3.2, Python 3.12): 125 passed, 1 skipped.Priority: high
What happened
mainno longer contains #99, although it was merged:47712d0) and [high] Exit non-zero and keep converting when a rule fails with --output-dir #98 (c8348d7) were merged on 2026-09-27 before [high] Write finalized, postprocessed queries with --output-dir #105.main. The resolution86d3041("Merge github/main: resolve conflicts in convert.py and test_convert.py") brought [high] Exit non-zero and keep converting when a rule fails with --output-dir #98 and [high] Report collection errors and broken filters in sigma check #99 into the [high] Write finalized, postprocessed queries with --output-dir #105 branch, but it failstests/test_convert.py::test_convert_output_dir_basic(reproduced locally).cdd5436("Revert "Merge github/main: ...""), and [high] Write finalized, postprocessed queries with --output-dir #105 was merged with that revert (8effb4c). The revert removed the whole mergedmainside from the branch, so merging [high] Write finalized, postprocessed queries with --output-dir #105 took [high] Exit non-zero and keep converting when a rule fails with --output-dir #98's and [high] Report collection errors and broken filters in sigma check #99's changes back out ofmain:8effb4cdeletes the 22 lines [high] Report collection errors and broken filters in sigma check #99 added tosigma/cli/check.pyand its 51 lines of tests, and restores the old--output-direrror handling.Probably nobody intended to revert #98 and #99; they were collateral of undoing a broken conflict resolution.
Original description (#99)
BLUF
sigma checkonly reads the errors attached to rules inSigmaCollection.rules. It ignores errors that belong to no rule, such as an unknownaction:or an invalid filter (filters are stored inSigmaCollection.filters).sigma check --fail-on-error --fail-on-issues rules/passes (exit 0, "Found 0 errors") on a file thatsigma convert -t <backend> rules/rejects with "Errors found in Sigma rules". A CI gate built onsigma checklets these files through.load_and_check_rules()now also reports the entries ofSigmaCollection.errorsthat don't belong to a loaded rule. They count as rule errors, so--fail-on-errorapplies, and they are added to the--junitxmlreport. Per-rule errors, which pySigma also copies intoSigmaCollection.errors, are still counted once.mainand pass with the fix.Priority: high
Details
Root cause:
sigma/cli/check.py:130-175.load_and_check_rules()loops overrule_collection.rulesand readsrule.errors. It never readsrule_collection.errors, butsigma convertdoes, viacheck_rule_errors()(sigma/cli/rules.py:39-49). The two commands therefore disagree on:action: repaetraisesSigmaCollectionError. No rule is created, so the error lives only inSigmaCollection.errors.SigmaFilteris kept inSigmaCollection.filters, not in.rules, so its errors (for example an invalidid) are never seen.pySigma also puts every per-rule error into
SigmaCollection.errors(collection.pyerrors.extend(parsed_rule.errors)). The fix therefore skips errors that are already attached to a rule in.rules, compared by object identity. The count fortests/files/invalidstays at 6.Before:
After:
Testing
tests/test_check.py:test_check_unknown_collection_action(fails onmain)test_check_invalid_filter(fails onmain)test_check_collection_error_junitxml(fails onmain)test_check_rule_errors_not_double_counted(regression guard)poetry.lock: pySigma 1.4.0, click 8.4.2, pyparsing 3.3.2):pytest --cov=sigma→ 122 passed, 1 skipped.🤖 Generated with Claude Code