fix(notify): safe telegram html truncation#4877
fix(notify): safe telegram html truncation#4877timmilesdw wants to merge 1 commit intoprometheus:mainfrom
Conversation
Signed-off-by: Timur Tuktamyshev <timur.tuktamyshev@flant.com>
|
Hello! @simonpasquier @SuperQ can i get a review on this pr? |
|
I am not really shure it is a good idea. Is it HTLM sanitization really a functionality alertmanager should provide? There is some alternatives. |
Thanks for the feedback! I understand your concerns, but this is just a pretty simple and robust truncation function. This PR is not adding general-purpose HTML sanitization to Alertmanager. It does not attempt to clean, filter, or validate arbitrary user-supplied HTML. The alternatives you suggest are basically workarounds: limiting templates, using external adapters, or avoiding truncation entirely. Those can be useful, but they don’t address the underlying problem that Alertmanager itself produces invalid HTML when truncating. As a bonus, the same truncation function can be reused by other notifiers that produce HTML output (If there will be any). |
Fix telegram truncation breaking markup
I've come back 4 years later to fix the bug I introduced with telegram notifier in 2022.
Context:
When truncating telegram alert with HTML formatting, truncate function would cut off mid html tag, leaving malformed HTML. Added
TruncateInRunesHTMLfunction that fixes this bug. It tracks open tags while scanning and ensures that all the tags are properly closed. It finds the last safe cut point where we can fit the truncation marker plus all necesarry closing tags within the limit.Tested with unit tests which I also added, and also manually with a long alert message, looks something like this:
Closes related issue #2923