Fix pipeline conditions (index/source) placement with OR-ed regex - #66
Conversation
…ions When processing pipelines add conditions (index, source, etc.) and the rule contains OR-ed regex expressions, the conditions were being placed inside the `| search` clause instead of at the beginning of the query. This fix extracts Splunk metadata field conditions (index, source, sourcetype, host) from the query and places them before the deferred rex/eval pipeline commands for efficient data retrieval. Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
|
@copilot Instead of statically matching on certain condition parts in the #sym:finish_query method, the distinction can already be made while the conversion in #sym:convert_condition_field_eq_val_re and #sym:SplunkDeferredORRegularExpression by distinguishing between query expression parts that refer to fields created by the eval in #sym:SplunkDeferredORRegularExpression and fields that don't depend on this and can be moved to the beginning of the generated query. |
…namically Instead of hardcoded index/source/sourcetype/host regex matching, use SplunkDeferredORRegularExpression.get_all_condition_fields() to identify which leading query parts don't depend on deferred eval fields and can be moved before the rex/eval pipeline commands. Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Refactored in fdd5cd4. Removed the hardcoded |
|
@copilot a test fails, please fix. |
…mpat The prefix extraction in finish_query was breaking finalize_query_data_model because it altered the query format that data model handling expected. Now finish_query keeps the simple format (\n| rex...\n| eval...\n| search <query>) and stores the deferred condition field names on state. finalize_query_default uses those field names to extract non-deferred leading conditions and place them before the deferred pipeline commands. Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com> Agent-Logs-Url: https://github.com/SigmaHQ/pySigma-backend-splunk/sessions/a4e1c291-7dee-4028-96db-41812064da2a
Fixed in 4f3ca56. The prefix extraction in |
When a processing pipeline adds conditions via
add_condition(e.g.index,source) and the rule contains OR-ed regex expressions, those conditions get placed inside the trailing| searchclause instead of at the beginning of the query. This prevents Splunk from using them for efficient initial data retrieval.Before:
After:
Changes
sigma/backends/splunk/splunk.py: Addedget_all_condition_fields()class method toSplunkDeferredORRegularExpressionwhich returns the set of all condition field names created by deferred OR regex expressions. Infinish_query(), this set is stored instate.processing_state["deferred_or_condition_fields"]for use by finalize methods. The prefix extraction logic (moving non-deferred leadingfield=valueterms before therex/evalpipeline commands) is performed infinalize_query_default()rather thanfinish_query(), so thatfinalize_query_data_model()continues to receive the expected query format and is not affected. Added_field_eq_val_reclass-level pattern for matching leading field=value terms.tests/test_backend_splunk.py: Addedtest_splunk_regex_query_explicit_or_with_add_conditioncovering the exact scenario from the issue.Original prompt
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.