-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution][Response Ops] Rule actions sending malformed JSON when using {{context.alerts}}
action template
#137114
Comments
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
Could you provide some sample output here?
What is the value in
I haven't seen anyone successfully render an array of JSON values as a valid JSON value in the output, but I'd be interested to see what you try. The most relevant issue related to this is this one: #84217 - just had a quick thought on a low-cost way of adding better JSON support for arrays, and posted a comment there. |
I'm having this same issue and I've tried many different iterations of mustache templates to get the output to be valid json. The weird think here is that the email connector parses the mustache template properly and produces the expected result. {
"raw_json": [
{{#context.alerts}}
{{.}},
{{/context.alerts}}
{}
]
} The above renders as {
"raw_json": [{{context.alerts}}]
} [
{{#context.alerts}}
{
"raw_json": {{.}}
},
{{/contexst.alerts}}
{}
] This is really difficult to work with, especially since the elastic alerts can and for us most times will have multiple alerts per execution. A workaround I'm using for now is to render the json as follows and then parse the {
"raw_json": "[{{#context.alerts}}{{.}},{{/context.alerts}},{}]"
} |
I thought I'd mention that some users ran into a similar issue when not explicitly setting the content-type header to JSON. There was a 7.17 update that changed the underling axios version, and it was defaulting to a content-type of form. |
We use the webhook connector to send our alerts to our SOAR system internally. I responded to this discuss post with how we do it. https://discuss.elastic.co/t/elastic-rule-connector-sends-a-string-instead-of-json-to-the-webhook/313833 We send the entire contents of the alert body as an ndjson with this action template:
|
Hi, This issue came up as an sdh issue as well. Unfortunately there isn't built-in way in mustache to tackle this, but IMHO, we can do: 1- Create an issue to add an extra field (like This has to be approved by the @elastic/security-solution as they are the owner of the rule type. 2- We can try to replace trailing commas by using a regex in the webhook connector type executor.
|
Rule actions are failing to fire when using the
{{context.alerts}}
placeholder due to the JSON output being malformed when sent to the assigned webhook. This is causing502
errors to come back from the webhook and not properly fire when the rule executes successfully. When looking at the malformed output, the JSON is often arbitrarily cut off and not escaped properly which is causing it to error out.So far the action template we've used in testing has been
but we've also modified it with different forms of mustache syntax in the template and gotten similar, malformed results. This has also been tested on multiple different webhooks each with similar
502
outputs. The issue seems to consistently be occurring with the{{context.alerts}}
placeholder, but it's possible the issue is not limited to that field alone.In the SDH (internal link) this was originally discovered in, the same action template and rule action was working for a certain rule while failing for others, leading us to believe maybe it has something to do with the alerts themselves not meshing well with the mustache formatting or something to that effect.
We've triaged it to the
formatAlertsForNotificationActions
sending alerts to the alerting framework in this file as still working and sending valid JSON so presumably the bug is downstream from that.The text was updated successfully, but these errors were encountered: