copy subset of Sprig template functions

This commit is contained in:
Hunter Kehoe
2025-07-07 22:23:32 -06:00
parent 3c8ac4a1e1
commit 1f2c76e63d
53 changed files with 5550 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ import (
"heckel.io/ntfy/v2/log"
"heckel.io/ntfy/v2/user"
"heckel.io/ntfy/v2/util"
"heckel.io/ntfy/v2/util/sprig"
)
// Server is the main server, providing the UI and API for ntfy
@@ -1132,7 +1133,11 @@ func replaceTemplate(tpl string, source string) (string, error) {
if err := json.Unmarshal([]byte(source), &data); err != nil {
return "", errHTTPBadRequestTemplateMessageNotJSON
}
t, err := template.New("").Parse(tpl)
sprigFuncs := sprig.FuncMap()
// remove unsafe functions
delete(sprigFuncs, "env")
delete(sprigFuncs, "expandenv")
t, err := template.New("").Funcs(sprigFuncs).Parse(tpl)
if err != nil {
return "", errHTTPBadRequestTemplateInvalid
}