add json.dumps to fix multiline escape issue#6074
Closed
wingiti wants to merge 1 commit into
Closed
Conversation
wingiti
commented
May 5, 2026
| if multiline: | ||
| if raw: | ||
| return "".join([TRIPLE_DQ, *initial_newline, *lines, TRIPLE_DQ]) | ||
| return "".join([TRIPLE_DQ] + initial_newline + [json.dumps(line.strip("\n"))[1:-1] + "\n" for line in lines] + [TRIPLE_DQ]) |
Contributor
Author
There was a problem hiding this comment.
This will fix the issue with the filter but will break the fields "note", "setup", "description", "osquery" if they are multiline as they are somehow additionally escaped below in lines 250-271.
Same issue applies to fix in PR #6000
Filter needs to be handled in another way or, from my perspective preferred, multiline should be escaped in general (like in this PR) but lines 250-271 needs to be removed. As I don't know what impact this might have I will wait for some further feedback for now.
Contributor
There was a problem hiding this comment.
For more details on this see: https://github.com/elastic/detection-rules/pull/6000/changes#r3191141974
5 tasks
5 tasks
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.
Pull Request
Issue link(s): Related #6071
Summary - What I changed
I changed the return value to be also json dumped for "multiline Triple Double Quoted" stuff.
Because it is also done for Triple Single Quoted things and usual single lines which don't have this issue.
Issue before fix:

Backslashes will not be escaped here and therefore will get lost when saved as toml file:
Single line string for example will be escaped:

The fix probably looks a little bit ugly as I had to remove the last line break before dumping and then adding it again.
I tried to do the dump already one step before at:
detection-rules/detection_rules/rule_formatter.py
Line 88 in 0b15511
But this broke other things.
How To Test
Checklist
bug,enhancement,schema,maintenance,Rule: New,Rule: Deprecation,Rule: Tuning,Hunt: New, orHunt: Tuningso guidelines can be generatedmeta:rapid-mergelabel if planning to merge within 24 hoursContributor checklist