An XPath expression is built from a value taken from an HTTP request

tx0/go:request-value-in-xpathrecommendedwarningsecurity/injectiondepth fastsecurity, cwe-643

What it finds

xmlquery.Find(doc, "//user[name='"+r.FormValue("name")+"']"): a value from the request becomes part of an XPath expression, so a quote in it ends the literal and the client can widen the query to nodes it was not meant to see, such as every user. A value is compared through a variable bound outside the expression, or checked against a strict pattern before it is used.

The expression is the argument of Compile, MustCompile and Select of github.com/antchfx/xpath, of Parse and MustParse of goxpath, and the second argument of Find, FindOne, Query and QueryAll of xmlquery and htmlquery. It holds a request value as described for the request values of the pack.

From the rule's source, request_value_in_xpath.rs.

Example from the rule's tests
package p import (	"net/http" 	"github.com/antchfx/xmlquery") func find(doc *xmlquery.Node, w http.ResponseWriter, r *http.Request) {	user := r.FormValue("user")	xmlquery.Find(doc, "//user[name='"+user+"']")tx0 reports: xmlquery.Find is given an expression built from the request	xmlquery.Find(doc, "//user")}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:request-value-in-xpath" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:request-value-in-xpath] reason="..."

tx0 explain tx0/go:request-value-in-xpath shows the same in the terminal. Found a false positive? Report it.