XPath Injection

Detects XPath queries built from user input without escaping, enabling authentication bypass and data disclosure.

zakirkun 2558a16 2 files · 3.3 KB Updated

File contents

XPath Injection

Overview

XPath injection is analogous to SQL injection but targets XML documents. An attacker can manipulate XPath expressions to bypass authentication, access unauthorized data nodes, or cause denial of service.

Classic bypass: ' or '1'='1 in username field when query is //user[name/text()='{username}']

Remediation

Use parameterized XPath (XQuery with bound variables) or escape user input using library-provided escaping functions.

Vulnerable (Java):

String query = "//user[name='" + username + "' and password='" + password + "']";
NodeList nodes = (NodeList) xpath.evaluate(query, doc, XPathConstants.NODESET);

Safe (Java):

// Use parameterized XQuery or properly escape the input

zakirkun/ice-tea/tree/main/skills/injection/xpath-injection commit 2558a16bdb

Frequently asked questions

npx skillmds@latest add zakirkun/xpath-injection