1 XPath Injection Basics
XPath injection is analogous to SQL injection but targets XML data stores. When user input is concatenated into an XPath query string, attackers can alter the query logic to bypass authentication or extract unauthorized data.
Vulnerable example (PHP):
$username = $_POST["username"];
$password = $_POST["password"];
$xml = simplexml_load_file("users.xml");
$result = $xml->xpath("//user[username='$username' and password='$password']");An attacker sends username ' or '1'='1 to produce:
//user[username='' or '1'='1' and password='anything']This returns all user nodes, bypassing authentication. Attackers can also extract the entire XML document structure using techniques like ] | //* | //foo[a='.