XSS (ARCH5101)
Ce contenu n’est pas encore disponible dans votre langue.
Key go.security.xss · Severity error · Category security · CWE CWE-79
Writing user input to HTML output without escaping (for example via template.HTML, which disables auto-escaping) lets attackers inject scripts.
Incorrect
Section titled “Incorrect”func page(w http.ResponseWriter, r *http.Request) { name := r.URL.Query().Get("name") t := template.Must(template.New("p").Parse("<h1>{{.}}</h1>")) t.Execute(w, template.HTML(name)) // escaping bypassed}Correct
Section titled “Correct”func page(w http.ResponseWriter, r *http.Request) { name := r.URL.Query().Get("name") t := template.Must(template.New("p").Parse("<h1>{{.}}</h1>")) t.Execute(w, name) // html/template auto-escapes}Rely on html/template auto-escaping; do not convert user input into types like template.HTML.