Why it matters
If the response is served as HTML, markup in the value runs as script in the user's browser.
How to fix it
Render the value through html/template, which escapes for the context it lands in, or escape it with html.EscapeString. Do not convert request data to template.HTML.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
package fixture
import (
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
name := r.FormValue("name")
fmt.Fprintf(w, "<h1>Hello %s</h1>", name)
}package fixture
import (
"fmt"
"html"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
name := html.EscapeString(r.FormValue("name"))
fmt.Fprintf(w, "<h1>Hello %s</h1>", name)
}What TrustIvan reads
Runs on repository scans of Go source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- SSRF from request input (Go)
GoSeverity: High
trustivan-go-taint-ssrf - Deserialization from request input (Go)
GoSeverity: Medium
trustivan-go-taint-deserialization - Path traversal from request input (Go)
GoSeverity: High
trustivan-go-taint-path-traversal - Open redirect from request input (Go)
GoSeverity: Medium
trustivan-go-taint-open-redirect - Command injection from request input (Go)
GoSeverity: High
trustivan-go-taint-command-injection - Template injection from request input (Go)
GoSeverity: High
trustivan-go-taint-template-injection
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation