I am using XPath to retrieve values from XML. My code scanner break the build because of the following reason:
invokes an XPath query built using unvalidated input. This call could allow an attacker to modify the statement's meaning or to
This is my code:
private String myMethod(String XPath, OMElement input) {
String elementText = null;
AXIOMXPath xpathToElement = null;
try {
xpathToElement = new AXIOMXPath(XPath);
xpathToElement.addNamespace(xxx,yyy);
elementText = ((OMElement) xpathToElementnode.selectSingleNode(input)).getText();
} catch (JaxenException e) {
e.printStackTrace();
fail(e.getMessage());
...
Here is the code where I call above method:
key = myMethod(myAttribute.getAttributeValue(), input);
input
is OMelement
which contains XML. Attribute is getting from XML attribute.
How can I avoid XPathInjection? Could please share a code snippet?