argocd-notifications icon indicating copy to clipboard operation
argocd-notifications copied to clipboard

Template issue using {{.app.status.operationState.message}}

Open EdYa opened this issue 3 years ago • 4 comments

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.

EdYa avatar Mar 08 '21 12:03 EdYa

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.

jutley avatar Mar 23 '21 00:03 jutley

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 "\"" "\\\""}}".

jutley avatar Mar 23 '21 00:03 jutley

I found more success using :

"key": {{message | toJson}}

It handles line breaks too.

MrSaints avatar Apr 25 '21 23:04 MrSaints

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.

tsunamishaun avatar May 18 '21 18:05 tsunamishaun