diff --git a/app/src/main/java/biweekly/io/xml/XCalDocument.java b/app/src/main/java/biweekly/io/xml/XCalDocument.java index 5c24754bc7..4f3211f1d8 100644 --- a/app/src/main/java/biweekly/io/xml/XCalDocument.java +++ b/app/src/main/java/biweekly/io/xml/XCalDocument.java @@ -471,7 +471,9 @@ public class XCalDocument { public void write(Writer writer, Map outputProperties) throws TransformerException { Transformer transformer; try { - transformer = TransformerFactory.newInstance().newTransformer(); + TransformerFactory factory = TransformerFactory.newInstance(); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + transformer = factory.newTransformer(); } catch (TransformerConfigurationException e) { //should never be thrown because we're not doing anything fancy with the configuration throw new RuntimeException(e); diff --git a/app/src/main/java/biweekly/io/xml/XCalReader.java b/app/src/main/java/biweekly/io/xml/XCalReader.java index 4817d7847b..89ce066a59 100644 --- a/app/src/main/java/biweekly/io/xml/XCalReader.java +++ b/app/src/main/java/biweekly/io/xml/XCalReader.java @@ -206,6 +206,7 @@ public class XCalReader extends StreamReader { //create the transformer try { TransformerFactory factory = TransformerFactory.newInstance(); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); XmlUtils.applyXXEProtection(factory); transformer = factory.newTransformer(); diff --git a/app/src/main/java/biweekly/util/XmlUtils.java b/app/src/main/java/biweekly/util/XmlUtils.java index e2188d079d..15fad95c7c 100644 --- a/app/src/main/java/biweekly/util/XmlUtils.java +++ b/app/src/main/java/biweekly/util/XmlUtils.java @@ -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 @@ -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 @@ -283,7 +290,9 @@ public final class XmlUtils { */ public static void toWriter(Node node, Writer writer, Map 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 property : outputProperties.entrySet()) { try { transformer.setOutputProperty(property.getKey(), property.getValue()); diff --git a/app/src/main/java/com/bugsnag/android/repackaged/dslplatform/json/XmlConverter.java b/app/src/main/java/com/bugsnag/android/repackaged/dslplatform/json/XmlConverter.java index ddd88e99af..7ed5cfe6cb 100644 --- a/app/src/main/java/com/bugsnag/android/repackaged/dslplatform/json/XmlConverter.java +++ b/app/src/main/java/com/bugsnag/android/repackaged/dslplatform/json/XmlConverter.java @@ -39,6 +39,7 @@ public abstract class XmlConverter { static { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); try { + dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); documentBuilder = dbFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); diff --git a/app/src/main/java/com/sun/mail/handlers/text_xml.java b/app/src/main/java/com/sun/mail/handlers/text_xml.java index 1f0301793c..2c578c8c8a 100644 --- a/app/src/main/java/com/sun/mail/handlers/text_xml.java +++ b/app/src/main/java/com/sun/mail/handlers/text_xml.java @@ -79,8 +79,9 @@ public class text_xml extends text_plain { } 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(); StreamResult result = new StreamResult(os); if (obj instanceof DataSource) { // Streaming transform applies only to