Ir al contenido

Template Injection (ARCH5130)

Esta página aún no está disponible en tu idioma.

Key go.security.template-injection · Severity error · Category security · CWE CWE-1336

Building the template text itself from user input lets attackers inject template directives (SSTI) and execute code on the server.

func render(w http.ResponseWriter, r *http.Request) {
src := "Hello " + r.URL.Query().Get("name")
t := template.Must(template.New("p").Parse(src))
t.Execute(w, nil)
}
var tmpl = template.Must(template.New("p").Parse("Hello {{.Name}}"))
func render(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, struct{ Name string }{r.URL.Query().Get("name")})
}

Compile templates from fixed sources and pass user input only as data, never into the template text.