Home / Knowledge hub / XPath injection
Knowledge hub
XPath injection
Input that changes an XPath query run against XML data.
What it means
XPath is a language for picking items out of an XML document, for example the user whose name and password match what was typed. XPath injection happens when that typed text is pasted into the query string, so the text can change the query instead of just filling a gap in it.
It follows the same pattern as SQL injection. The attacker adds quotes and conditions that make the query true for every record, or that reveal information one character at a time. The application is the one that runs the altered query.
Why it matters
XPath has no built-in permission layer. A query that runs against a document can usually read any part of it, so one injected condition may expose data well outside the intended record. Sign-in checks that use XPath can be bypassed, and stored configuration or user lists can leak.
Because XML documents often hold credentials, settings or customer records in older systems, the exposure can be wide. MITRE tracks the weakness as CWE-643, and OWASP lists it among injection attacks. A flaw like this is also easy to overlook, because it hides in the parts of a system that nobody has reviewed for years.
How it shows up
You meet it in older enterprise software, SOAP services, applications that keep users or settings in XML files, and any feature that searches XML supplied by customers. The standard mistake is building the query by joining strings, such as //user[name='INPUT' and pass='INPUT'].
Use parameterised XPath where your library supports variables, so values travel separately from the query. Otherwise escape quotes properly and validate input against an allowlist. Keep sensitive data out of documents that every query can read. Test with quote characters and always-true conditions. See injection and SQL injection.
Questions people ask
XPath injection, answered
Is XPath injection the same as SQL injection?
It is the same idea against a different query language. Input changes the meaning of the query.
XPath gives the attacker an extra advantage, because there is usually no access control inside the document being queried.
What does blind XPath injection mean?
It means the page shows no data or error, but its behaviour changes with the injected condition. The attacker asks yes or no questions and reads the answer from the difference.
It is slower, but it can still extract a whole document.
How do we prevent XPath injection?
Pass values as parameters through variables where possible, and validate or escape every value placed in a query. Never concatenate raw input.
Reduce what a single query can reach by splitting sensitive data into separate documents.
Do we still use XPath in modern apps?
Often more than expected: SOAP services, XML configuration, document processing and some report tools all use it.
It is easy to overlook because it sits in older components. Include these components in any test.
How do we test for it?
Enter a single quote and always-true conditions in fields that search or sign in against XML, and compare the response to normal input.
A change in behaviour, an error, or extra records points to an unsafe query.
Sources
Where this comes from
Related
Terms that sit next to this one
Injection
Input that ends up running as a command instead of being read as text.
SQL injection
Input a database ends up running as part of a query.
LDAP injection
Input that alters a directory lookup, such as a sign-in or user search.
XXE
An XML parser tricked into fetching files or internal addresses.
Parameterised queries
Sending the query and the data separately so input can never become code.
Can input rewrite the question?
Older XML-backed features are easy to forget. We test the inputs that reach those queries and report what changed in the response, with the request that proves it. Book a pilot on one app.
Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.