Fix generate_logformat_regex to escape regex metacharacters in literal format segments#85
Draft
Fix generate_logformat_regex to escape regex metacharacters in literal format segments#85
Conversation
…teral parts Co-authored-by: viktorbeck98 <95294548+viktorbeck98@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix get_configured_variables detection for type=login
Fix generate_logformat_regex to escape regex metacharacters in literal format segments
Mar 11, 2026
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.
generate_logformat_regexwas not escaping regex metacharacters in the literal parts of a log format string. For the audit log formattype=<Type> msg=audit(<Time>): <Content>, the unescaped(and)flanking<Time>acted as regex group delimiters, causingTimeto capture the surrounding parentheses:_extract_timestampinCoreDetector.rundoesint(float(time.split(":")[0])), which raisedValueErroron the leading(, causing detection to fail for every log entry processed through a detector with this format — most visibly fortype=LOGIN(the third distinct line inaudit.log).Changes
utils/log_format_utils.py—generate_logformat_regex: replace the barere.sub(r' +', ...)substitution with splitting on whitespace runs, applyingre.escape()to each part, and rejoining with\s+. This correctly escapes all regex metacharacters while preserving multi-space-to-\s+semantics.tests/test_utils/test_log_format_utils.py— AddTestGenerateLogformatRegexcovering: basic format parsing, parentheses-in-literal escaping across all three audit log entry types (includingLOGIN), and verifying the extracted timestamp is parseable by_extract_timestamp.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.