Sonar proposes compliant solution for SchemaFactory as follows:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// to be compliant, completely disable DOCTYPE declaration:
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// or prohibit the use of all protocols by external entities:
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
It clearly says disable DOCTYPE declaration or prohibit the use of all protocols by external entities so I chose the 1st option.
Any clues how to fix this without setting external properties? Is it a bug in Sonar or am I missing something? I used newInstance()
with specific factory class argument but I don't think it should influence the security rule.