XPath Injection (ARCH5108)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key go.security.xpath-injection · Severity error · Category security · CWE CWE-643
An XPath expression assembled from input (xpath.Compile, htmlquery.FindOne(doc, ...), xmlquery.Find) lets the caller rewrite the query - ' or '1'='1 selects every node.
Incorrect
Section titled “Incorrect”expr := fmt.Sprintf("//user[@name='%s']", name)node := htmlquery.FindOne(doc, expr)Correct
Section titled “Correct”if !validName.MatchString(name) { return ErrBadName}node := htmlquery.FindOne(doc, "//user[@name='"+strings.ReplaceAll(name, "'", "")+"']")Validate the value against an allowlist pattern before it enters the expression, or select by a literal path and compare attributes in Go.