I need to fix the code below for XML Data Injection.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(xmlFromWebService));
Document doc = db.parse(inStream); // reported at this line by a code audit tool
doc.getDocumentElement().normalize();
How to fix it? Do anyone have any suggestions.
I’m guessing that this has to do with validation of your XML against a given XSD to prevent XML Data Injection. I would suggest modifying your code like this:
I hope you get the hint!