-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go: promote html-template-escaping-bypass-xss
#19386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Go: promote html-template-escaping-bypass-xss
#19386
Conversation
QHelp previews: go/ql/src/Security/CWE-079/HtmlTemplateEscapingBypassXss.qhelpHTML template escaping bypass cross-site scriptingIn 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"
)
func bad(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"
)
func good(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)
} |
896cf81
to
bef38a4
Compare
Promoting this experimental XSS query.