Bugfix/incorrect evaluation of deferred regular expressions#30
Bugfix/incorrect evaluation of deferred regular expressions#30suryamajhi wants to merge 7 commits intologpoint:mainfrom
Conversation
…. Need to see if automatic conversion to snake_case makes sense for azure and m365. In future, if there happens to be it's need we shall add them. Also this section is for unusal hack for json_values.
There was a problem hiding this comment.
Pull request overview
This PR fixes the incorrect evaluation of deferred regular expressions in the Logpoint backend, ensuring proper handling of OR/AND/NOT operations when multiple regex modifiers are present in Sigma rules.
Changes:
- Modified regex processing to use group capturing instead of direct filtering, generating intermediate fields (
re1,re2, etc.) that are subsequently used in search expressions - Updated the query generation logic to correctly handle OR, AND, and NOT operations with regex patterns
- Reverted field mapping functions in M365 and Azure pipelines to simpler implementations
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sigma/backends/logpoint/logpoint.py | Core logic changes to implement group-capturing regex with proper substitution and query finalization |
| tests/test_backend_logpoint.py | Added comprehensive test cases for single, OR, AND, and NOT regex operations |
| sigma/pipelines/logpoint/m365.py | Simplified field mapping by removing snake_case conversion logic |
| sigma/pipelines/logpoint/azure.py | Simplified field mapping by removing snake_case conversion logic |
| pyproject.toml | Updated pysigma dependency version requirement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sigma/backends/logpoint/logpoint.py
Outdated
| for dt_item in detection_item.detection_items: | ||
| self._recursively_substitute_sigma_items(dt_item, orig_field, new_field) | ||
| else: | ||
| assert "Should not reach here" |
There was a problem hiding this comment.
The assert statement with a string message is not a proper error handling mechanism. Replace with raise SigmaError('Unexpected detection item type') to provide a meaningful error when an unexpected type is encountered.
| assert "Should not reach here" | |
| raise SigmaError("Unexpected detection item type") |
sigma/backends/logpoint/logpoint.py
Outdated
| detection_item.field = new_field | ||
| # Overriding the regex modifier | ||
| detection_item.modifiers = [] | ||
| # On successful regex match, a new field is add with any value. So re1=* would suffice and filter the results. |
There was a problem hiding this comment.
Corrected grammar from 'a new field is add' to 'a new field is added'.
| # On successful regex match, a new field is add with any value. So re1=* would suffice and filter the results. | |
| # On successful regex match, a new field is added with any value. So re1=* would suffice and filter the results. |
swachchhanda000
left a comment
There was a problem hiding this comment.
BTW @suryamajhi,
what happens when '|re' modifier has value as a list.
fieldA|re:
- 'regex1'
- 'regex2'
|
@swachchhanda000 , Currently it does foloowing: This is wrong as re2 is ignored here. |
|
Hi @swachchhanda000 , Major changes:
Sigma: LP Query: Other test cases related to regex are updated in test file as well. See other examples if needed. |
|
I will close this PR and create new one with updated implementation changes. |
Summary
This PR fixes the incorrect evalution of deferred regular expression.
Problem Statement
In presence of any regex modifier, it always does AND operation among them.
Example sigma:
Current output:
The result of this query is AND operation as both of them are filtering on truth case. But actually, it has to be an OR operation. Also, there is no regards for NOT operation.
Solution
Instead of directly adding the filter=true in regex process command, let the regex process command execute with group capturing. If the regex match was success, then the captured group field is added in the log. Later use that new field to correctly substitute in the sigma expression.
Sigma Example 1:
Output:
This output correctly express sigma rule as re1 and re2 will be populated accordingly.
Sigma Example 2 (Negation on regex modifier):
Output: