If an XPath expression is built using string concatenation, and the components of the concatenation include user input, it makes it very easy for a user to create a malicious XPath expression.

If user input must be included in an XPath expression, either sanitize the data or use variable references to safely embed it without altering the structure of the expression.

In the example below, the xpath query is controlled by the user and hence leads to a vulnerability.

This can be fixed by using a parameterized query as shown below.

  • OWASP XPath injection : />>