From 807d057f7bda8831d970df5315e1b9954ac87dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 13 Mar 2026 09:03:39 +0100 Subject: [PATCH] stdlib: remove duplicate err check in New() and add XML escaping to user-controlled template values Remove the dead second 'if err != nil' block after the already-checked lib.Templates assignment. Add html.EscapeString as 'xmlesc' template function and apply it to user-controlled string parameters in ac:code, ac:status, and ac:box templates. Values like .Title, .Color, .Language, and .Theme can contain XML special characters (<, >, &, ") when supplied by users, which would break Confluence storage format XML structure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- stdlib/stdlib.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index fbe1327..d31d938 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -1,6 +1,7 @@ package stdlib import ( + "html" "strings" "text/template" @@ -25,10 +26,6 @@ func New(api *confluence.API) (*Lib, error) { return nil, err } - if err != nil { - return nil, err - } - return &lib, nil } @@ -67,6 +64,9 @@ func templates(api *confluence.API) (*template.Template, error) { "_", ) }, + "xmlesc": func(s string) string { + return html.EscapeString(s) + }, }, ) @@ -90,20 +90,20 @@ func templates(api *confluence.API) (*template.Template, error) { // This template is used for rendering code in ``` `ac:code`: text( ``, - /**/ `{{ .Language }}`, + /**/ `{{ .Language | xmlesc }}`, /**/ `{{ .Collapse }}`, - /**/ `{{ if .Theme }}{{ .Theme }}{{ end }}`, + /**/ `{{ if .Theme }}{{ .Theme | xmlesc }}{{ end }}`, /**/ `{{ if .Linenumbers }}{{ .Linenumbers }}{{ end }}`, /**/ `{{ if .Firstline }}{{ .Firstline }}{{ end }}`, - /**/ `{{ if .Title }}{{ .Title }}{{ end }}`, + /**/ `{{ if .Title }}{{ .Title | xmlesc }}{{ end }}`, /**/ ``, ``, ), `ac:status`: text( ``, - `{{ or .Color "Grey" }}`, - `{{ or .Title .Color }}`, + `{{ or .Color "Grey" | xmlesc }}`, + `{{ or .Title .Color | xmlesc }}`, `{{ or .Subtle false }}`, ``, ), @@ -161,7 +161,7 @@ func templates(api *confluence.API) (*template.Template, error) { `ac:box`: text( ``, `{{ or .Icon "false" }}`, - `{{ if .Title }}{{ .Title }}{{ end }}`, + `{{ if .Title }}{{ .Title | xmlesc }}{{ end }}`, `{{ .Body }}`, ``, ),