Kotlin Xpath Injection Unvalidated Input
Description
Detects XPath injection vulnerabilities in Kotlin code where untrusted input is used in XPath queries without proper validation. This could allow attackers to manipulate XPath queries and potentially access unauthorized data from XML documents.
Detection Strategy
• Check if javax.xml.xpath library is imported in the codebase
• Identify calls to XPath query execution methods
• Determine if the XPath query string contains data from external/user input without proper sanitization
• Report vulnerability if unsanitized external input flows into XPath operations
Vulnerable code example
import javax.servlet.http.HttpServletRequest
import javax.xml.xpath.XPathFactory
import org.xml.sax.InputSource
import java.io.StringReader
fun vulnerableXPathQuery(request: HttpServletRequest) {
val xmlDoc = "<users><user><name>admin</name><pass>secret</pass></user></users>"
val xpath = XPathFactory.newInstance().newXPath()...✅ Secure code example
import javax.servlet.http.HttpServletRequest
import javax.xml.xpath.XPathFactory
import javax.xml.xpath.XPathExpression
import javax.xml.xpath.XPathConstants
import org.xml.sax.InputSource
import java.io.StringReader
fun secureXPathQuery(request: HttpServletRequest) {...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.