Why it matters
A quote in the value changes which nodes it selects.
How to fix it
Validate the value against a strict pattern (for example digits only) before placing it in the expression, or walk the tree in code.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
package catalog
import (
"net/http"
"github.com/antchfx/xmlquery"
)
func Item(w http.ResponseWriter, r *http.Request, doc *xmlquery.Node) {
sku := r.FormValue("sku")
node := xmlquery.FindOne(doc, "//item[@sku='"+sku+"']")
_, _ = w.Write([]byte(node.InnerText()))
}package catalog
import (
"net/http"
"github.com/antchfx/xmlquery"
)
func Item(w http.ResponseWriter, r *http.Request, doc *xmlquery.Node) {
sku := r.FormValue("sku")
for _, n := range xmlquery.Find(doc, "//item") {
if n.SelectAttr("sku") == sku {
_, _ = w.Write([]byte(n.InnerText()))
}
}
}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
- LDAP injection from request input (Go)
GoSeverity: High
trustivan-go-taint-ldap-injection - Regex injection from request input (Go)
GoSeverity: Medium
trustivan-go-taint-regex-injection - Text template HTML response (Go)
GoSeverity: Medium
trustivan-go-text-template-html-response - NoSQL injection from request input (Go)
GoSeverity: High
trustivan-go-taint-nosql-injection - Pprof exposed (Go)
GoSeverity: Medium
trustivan-go-pprof-exposed - Code injection from request input (Go)
GoSeverity: High
trustivan-go-taint-code-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