Aller au contenu

XPath injection (ARCH318)

Ce contenu n’est pas encore disponible dans votre langue.

Key dotnet.security.xpath-injection · Severity error · Category security · CWE CWE-643

Concatenating user input into an XPath expression lets an attacker alter the query and reach unauthorized nodes. Use variables.

var node = doc.SelectSingleNode(
"/users/user[name='" + userName + "']");
var expr = nav.Compile("/users/user[name=$name]");
var ctx = new CustomContext(); // resolves $name to a bound value
expr.SetContext(ctx);
var node = nav.SelectSingleNode(expr);

Use XPathExpression variables/bound parameters instead of concatenating input as a string.