nyx/tests/fixtures/ssti/go/safe_template_constant.go
2026-05-07 01:29:31 -04:00

20 lines
512 B
Go

// Safe: text/template parsed from a constant source string; user input
// flows into the data argument of `Execute`, which is rendered via the
// template's escape policy (not as source).
package ssti
import (
"net/http"
"text/template"
)
func HandlerSafe(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
tpl, err := template.New("x").Parse("Hello, {{.Name}}")
if err != nil {
http.Error(w, err.Error(), 500)
return
}
tpl.Execute(w, struct{ Name string }{Name: name})
}