Skip to content

Fix AddConditionTransformation to handle empty conditions - #405

Merged
thomaspatzke merged 2 commits into
mainfrom
copilot/fix-condition-transformation-issue
Nov 9, 2025
Merged

Fix AddConditionTransformation to handle empty conditions#405
thomaspatzke merged 2 commits into
mainfrom
copilot/fix-condition-transformation-issue

Conversation

Copilot AI commented Nov 2, 2025

Copy link
Copy Markdown
Contributor

When all query terms are deferred (e.g., Splunk regex expressions), the condition string becomes empty. AddConditionTransformation was creating invalid conditions like "additional and ()" instead of "additional".

Changes

  • sigma/processing/transformations/condition.py: Modified apply_condition() to check if condition is empty before wrapping in parentheses
  • tests/test_processing_transformations.py: Added tests for empty condition scenarios with and without negation

Example

# Before: empty condition → "additional and ()"
# After: empty condition → "additional"

rule.detection.parsed_condition[0].condition = ""  # e.g., all items deferred
transformation = AddConditionTransformation({"EventID": 1}, "additional")
transformation.apply(rule)
# Result: "additional" (not "additional and ()")
Original prompt

This section details on the original issue you should resolve

<issue_title>Add Condition Transformation not applied if condition is empty</issue_title>
<issue_description>This is required if all query terms are moved into deferred query parts, eg Splunk regular expressions. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix condition transformation not applied when empty Fix AddConditionTransformation to handle empty conditions Nov 2, 2025
Copilot AI requested a review from thomaspatzke November 2, 2025 01:15
@thomaspatzke
thomaspatzke marked this pull request as ready for review November 9, 2025 09:36
@thomaspatzke
thomaspatzke merged commit 130d27c into main Nov 9, 2025
24 checks passed
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.

Add Condition Transformation not applied if condition is empty

2 participants