mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-18 02:55:00 +03:00
fix(tgbot): escape template parameters once in I18nBot
Every bot message is sent HTML-parsed while the intended markup lives in the translation templates, yet the values filled into them were escaped only at some call sites. Remarks and e-mails, which a node chooses for the inbounds it reports, reached the scheduled report and the client info unescaped and turned into markup, and the reports that escaped their whole text instead showed the templates' own tags. I18nBot now escapes every parameter value, the call sites drop their own escaping and the whole-report escapes, the two values concatenated outside a template are escaped where they are written, and callback answers, which are plain text, are unescaped again.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"embed"
|
||||
"fmt"
|
||||
"html"
|
||||
"math/big"
|
||||
"net"
|
||||
"net/url"
|
||||
@@ -249,9 +250,19 @@ func (t *Tgbot) NewTgbot() *Tgbot {
|
||||
return new(Tgbot)
|
||||
}
|
||||
|
||||
// I18nBot retrieves a localized message for the bot interface.
|
||||
// I18nBot retrieves a localized message for the bot interface. Every message is sent
|
||||
// HTML-parsed, so param values (remarks, e-mails, errors) are escaped here.
|
||||
func (t *Tgbot) I18nBot(name string, params ...string) string {
|
||||
return locale.I18n(locale.Bot, name, params...)
|
||||
escaped := make([]string, len(params))
|
||||
for i, param := range params {
|
||||
key, value, found := strings.Cut(param, "==")
|
||||
if !found {
|
||||
escaped[i] = param
|
||||
continue
|
||||
}
|
||||
escaped[i] = key + "==" + html.EscapeString(value)
|
||||
}
|
||||
return locale.I18n(locale.Bot, name, escaped...)
|
||||
}
|
||||
|
||||
// GetHashStorage returns the hash storage instance for callback queries.
|
||||
|
||||
Reference in New Issue
Block a user