Uh oh!
There was an error while loading. Please reload this page.
Go: promote html-template-escaping-bypass-xss - #19386
Conversation
QHelp previews: go/ql/src/Security/CWE-079/HtmlTemplateEscapingBypassXss.qhelpCross-site scripting via HTML template escaping bypassIn Go, the Using them on user-provided values allows for a cross-site scripting vulnerability. RecommendationMake sure to never use those types on untrusted content. ExampleIn the first example you can see the special types and how they are used in a template: package main
import (
"html/template""net/http"
)
funcbad(w http.ResponseWriter, r*http.Request) {
r.ParseForm()
username:=r.Form.Get("username")
tmpl, _:=template.New("test").Parse(`<b>Hi {{.}}</b>`)
tmpl.Execute(w, template.HTML(username))
}To avoid XSS, all user input should be a normal string type. package main
import (
"html/template""net/http"
)
funcgood(w http.ResponseWriter, r*http.Request) {
r.ParseForm()
username:=r.Form.Get("username")
tmpl, _:=template.New("test").Parse(`<b>Hi {{.}}</b>`)
tmpl.Execute(w, username)
} |
Uh oh!
There was an error while loading. Please reload this page.
896cf81 to
bef38a4Compare
smowton
left a comment
There was a problem hiding this comment.
Looks plausible if QA shows good results in practice; minor optional wording quibbles.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Chris Smowton <smowton@github.com>
owen-mc
commented
May 13, 2025
MRVA only found two repos with results (and one is deliberately vulnerable). I've started DCA on those repos. I also ran the query locally on the one which isn't deliberately vulnerable and looked at the tuple counts. They seemed fine - no predicate took longer than 361ms, and none of the slowest predicates seem related to this query. |
owen-mc
commented
Jun 6, 2025
I have checked autofix results and they are good enough. Ideally the alert message would contain a link to the step where the type conversion happens, but I do not think this is easy to do with the shared data flow library. |
Promoting this experimental XSS query.