XPath Injection exploits applications that construct XPath queries from user input to navigate or query XML documents. Attackers can inject malicious input to alter the query’s behavior, potentially bypassing security controls or manipulating the document’s contents. Since XPath syntax resembles SQL, it’s possible to craft SQL-like queries on XML data. This vulnerability arises when unsafe user input is embedded in runtime XPath query construction, leading to unintended query parsing.
Use parameterized XPath queries (e.g. using XQuery). This will help ensure separation between data plane and control plane. Properly validate user input. Reject data where appropriate, filter where appropriate and escape where appropriate. Make sure input that will be used in XPath queries is safe in that context.