Skip to content
Snippets Groups Projects
Commit 0f3cecde authored by Hugues.Cazeaux's avatar Hugues.Cazeaux
Browse files

chore: fixed Sonar issue

parent cdee6b92
No related branches found
No related tags found
No related merge requests found
......@@ -486,8 +486,17 @@ public class XMLTool {
private static void setSecureParameters(DocumentBuilderFactory factory) throws ParserConfigurationException {
// Disable external resources
try {
// to be compliant, completely disable DOCTYPE declaration:
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// or completely disable external entities declarations:
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
// or prohibit the use of all protocols by external entities:
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
// or disable entity expansion but keep in mind that this doesn't prevent fetching external entities
// and this solution is not correct for OpenJDK < 13 due to a bug: https://bugs.openjdk.java.net/browse/JDK-8206132
factory.setExpandEntityReferences(false);
} catch (IllegalArgumentException e) {
log.warn("Cannot disable external access: {}", e.getMessage());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment