diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/resource/XMLResource.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/resource/XMLResource.java index cf1e0cc83..ea4a209f3 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/resource/XMLResource.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/resource/XMLResource.java @@ -194,8 +194,13 @@ private void setDocumentBuilderSecurityFeatures(DocumentBuilderFactory dbf) { private void setTranformerFactorySecurityFeatures(TransformerFactory xformFactory) { boolean b = true; - b &= trySetFeature(XMLConstants.ACCESS_EXTERNAL_DTD, "", xformFactory::setAttribute); - b &= trySetFeature(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "", xformFactory::setAttribute); + boolean isAccessExternalDtdFeature = xformFactory.getFeature(XMLConstants.ACCESS_EXTERNAL_DTD); + boolean isAccessExternalStylesheet = xformFactory.getFeature(XMLConstants.ACCESS_EXTERNAL_STYLESHEET); + boolean isFeatureSecureProcessing = xformFactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING); + + b &= (isAccessExternalDtdFeature ? trySetFeature(XMLConstants.ACCESS_EXTERNAL_DTD, "", xformFactory::setAttribute) : true); + b &= (isAccessExternalStylesheet ? trySetFeature(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "", xformFactory::setAttribute) : true); + b &= (isFeatureSecureProcessing ? trySetFeature(XMLConstants.FEATURE_SECURE_PROCESSING, "", xformFactory::setAttribute) : true); if (!b) { XRLog.log(Level.SEVERE, LogMessageId.LogMessageId0Param.LOAD_UNABLE_TO_DISABLE_XML_EXTERNAL_ENTITIES);