Skip to content

fix(postprocessing): raise SigmaConfigurationError on invalid regex in ReplaceQueryTransformation - #523

Open
Romil2112 wants to merge 2 commits into
SigmaHQ:mainfrom
Romil2112:fix/replace-query-transformation-invalid-regex
Open

fix(postprocessing): raise SigmaConfigurationError on invalid regex in ReplaceQueryTransformation#523
Romil2112 wants to merge 2 commits into
SigmaHQ:mainfrom
Romil2112:fix/replace-query-transformation-invalid-regex

Conversation

@Romil2112

@Romil2112 Romil2112 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Two places in the codebase call re.compile() on user-supplied patterns without wrapping the call, so an invalid regex raises a bare re.error from the stdlib instead of the SigmaConfigurationError callers expect.

Every other transformation/condition that compiles a user-supplied pattern already wraps it:

Location Error raised
ReplaceStringTransformation SigmaRegularExpressionError
ExtractFieldsTransformation SigmaRegularExpressionError
ExternalSourceBaseTransformation SigmaConfigurationError
MatchValueCondition SigmaRegularExpressionError
ReplaceQueryTransformation bare re.error ← inconsistent
IncludeFieldCondition (mode=re) bare re.error ← inconsistent

Fix

Both fixed in this PR:

  1. sigma/processing/postprocessing.pyReplaceQueryTransformation.__post_init__: wrap re.compile(self.pattern) → raise SigmaConfigurationError

  2. sigma/processing/conditions/fields.pyIncludeFieldCondition.__post_init__ (also covers ExcludeFieldCondition, which inherits __post_init__): replace the bare list comprehension with a loop that wraps each re.compile() → raise SigmaConfigurationError

Changes

  • sigma/processing/postprocessing.py
  • sigma/processing/conditions/fields.py
  • tests/test_postprocessing_transformations.py: test_replace_query_transformation_invalid_regex
  • tests/test_processing_conditions.py: test_include_field_condition_invalid_re

Testing

All 1521 existing tests continue to pass; both new tests confirm the fixes.

Closes #522

…n ReplaceQueryTransformation

ReplaceQueryTransformation.__post_init__ called re.compile() without a
try/except, so an invalid pattern surfaced as a bare re.error rather
than the SigmaConfigurationError callers expect. Wraps the call to match
the pattern already used by ReplaceStringTransformation,
ExtractFieldsTransformation, and ExternalSourceBaseTransformation.

Adds a regression test that constructs ReplaceQueryTransformation with an
invalid pattern and asserts SigmaConfigurationError is raised.

Fixes SigmaHQ#522
…cludeFieldCondition

IncludeFieldCondition.__post_init__ compiled user-supplied field patterns
in a bare list comprehension with no error handling. An invalid regex
pattern raised re.error (stdlib) instead of SigmaConfigurationError,
inconsistent with every other condition and transformation in the codebase
that wraps re.compile().

ExcludeFieldCondition inherits __post_init__ from IncludeFieldCondition
and gets the fix for free.

Adds a regression test.
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.

ReplaceQueryTransformation raises bare re.error instead of SigmaConfigurationError for invalid patterns

1 participant