argocd-notifications
argocd-notifications copied to clipboard
Template issue using {{.app.status.operationState.message}}
When using the predifined app-sync-failed template the is an error in some cases. The error message ({{.app.status.operationState.message}}) can contain an object with strings which are marked by double quotes. This strings making the JSON file in the message body invalid. So the adressed webhook is failing due to invalid JSON.
Ran into this as well after upgrading from 0.7.0 to 1.0.2. Seems like there should be a templating function available to escape strings, but I haven't found anything yet.
It's not documented as far as I can see, but it looks like the sprig functions are available. I was able to use this to escape the strings in the message: "{{$c.message | replace "\"" "\\\""}}"
.
I found more success using :
"key": {{message | toJson}}
It handles line breaks too.
I've noticed the use of text/template
with the slack templating rather frustrating where I think html/template
might provide better encoding support. Since I'm iterating through the conditions and providing a brief error message encased in ``` code blocks, I dont think toJson
would work for me but would for others. Early on I recall having to constantly monitor failed notifications for unsafe strings, ran into one today. Thanks for the advice @MrSaints @jutley do you have any other pointers or maybe a way to eliminate my toil?
edit: I've removed error summaries from my slack notification templates, too hard to ensure strings are safe.