XPath injection (ARCH4108)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key java.security.xpath-injection · Severity error · Category security · CWE CWE-643
Building an XPath expression by concatenating untrusted input lets attackers alter the query to disclose XML data they should not reach or bypass authentication.
Incorrect
Section titled “Incorrect”String expr = "/users/user[name='" + name + "']";XPathExpression xp = XPathFactory.newInstance().newXPath().compile(expr);Correct
Section titled “Correct”XPath xpath = XPathFactory.newInstance().newXPath();xpath.setXPathVariableResolver(v -> name);XPathExpression xp = xpath.compile("/users/user[name=$name]");Use parameterized expressions with an XPath variable resolver; never concatenate input into the expression string.