Our SonarQube configuration is
SonarQube Community Edition 8.2 (build 32929)
SonarJava Code Analyzer for Java 6.1 (build 20866)
We’re using XMLInputFactory
to parse XML files from a string:
import javax.xml.stream.XMLInputFactory;
...
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
XMLEventReader reader = factory.createXMLEventReader(new StringReader(myXmlString));
Rule java:S2755 is triggered and marks these lines as incorrect. The rule’s description suggests to Disable XML external entity (XXE) processing which we already did. More specifically, we’re using the suggested solution from the rule’s description:
XMLInputFactory library:
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); // Compliant
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); // compliant
XMLEventReader eventReader = factory.createXMLEventReader(new FileReader("xxe.xml"));
The only difference between the suggested solution and our solution is the source of the XML content. However, this should not affect the security of the code.