|
|
|
@ -154,6 +154,11 @@ public final class XmlUtils {
|
|
|
|
|
factory.setNamespaceAware(true);
|
|
|
|
|
factory.setIgnoringComments(true);
|
|
|
|
|
applyXXEProtection(factory);
|
|
|
|
|
try {
|
|
|
|
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
|
|
|
|
} catch (ParserConfigurationException ex) {
|
|
|
|
|
throw new SAXException(ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentBuilder builder;
|
|
|
|
|
try {
|
|
|
|
@ -169,6 +174,7 @@ public final class XmlUtils {
|
|
|
|
|
/**
|
|
|
|
|
* Configures a {@link DocumentBuilderFactory} to protect it against XML
|
|
|
|
|
* External Entity attacks.
|
|
|
|
|
*
|
|
|
|
|
* @param factory the factory
|
|
|
|
|
* @see <a href=
|
|
|
|
|
* "https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Prevention_Cheat_Sheet#Java">
|
|
|
|
@ -198,6 +204,7 @@ public final class XmlUtils {
|
|
|
|
|
/**
|
|
|
|
|
* Configures a {@link TransformerFactory} to protect it against XML
|
|
|
|
|
* External Entity attacks.
|
|
|
|
|
*
|
|
|
|
|
* @param factory the factory
|
|
|
|
|
* @see <a href=
|
|
|
|
|
* "https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Prevention_Cheat_Sheet#Java">
|
|
|
|
@ -283,7 +290,9 @@ public final class XmlUtils {
|
|
|
|
|
*/
|
|
|
|
|
public static void toWriter(Node node, Writer writer, Map<String, String> outputProperties) throws TransformerException {
|
|
|
|
|
try {
|
|
|
|
|
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
|
|
|
|
TransformerFactory factory = TransformerFactory.newInstance();
|
|
|
|
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
|
|
|
|
Transformer transformer = factory.newTransformer();
|
|
|
|
|
for (Map.Entry<String, String> property : outputProperties.entrySet()) {
|
|
|
|
|
try {
|
|
|
|
|
transformer.setOutputProperty(property.getKey(), property.getValue());
|
|
|
|
|