An XPath query is built by concatenating or interpolating values

tx0/csharp:xpath-from-stringsrecommendedwarningsecurity/injectiondepth fastsecurity, cwe-643

What it finds

An XPath expression assembled from input lets the input change the query: a name such as ' or '1'='1 selects every node. Precompiled expressions with variables, or strict validation of the inserted value, keep data and query apart. The rule reports SelectNodes, SelectSingleNode, Evaluate, Select on navigators and XPathExpression.Compile whose query is a + with a non-literal operand or an interpolated string with holes.

From the rule's source, xpath_from_strings.rs.

Example from the rule's tests
using System.Xml; class Users{    XmlNode Find(XmlDocument doc, string name)    {        var all = doc.SelectNodes("/users/user");        return doc.SelectSingleNode("/users/user[@name='" + name + "']");tx0 reports: the XPath query of SelectSingleNode is built from values    }}
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/csharp:xpath-from-strings" = "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/csharp:xpath-from-strings] reason="..."

tx0 explain tx0/csharp:xpath-from-strings shows the same in the terminal. Found a false positive? Report it.