When using DocumentBuilderFactory
in Android, we are required to enforce some security features so that the XMLs can be safely processed. The following are the flags we are trying to set
http://apache.org/xml/features/disallow-doctype-decl
or http://apache.org/xml/features/nonvalidating/load-external-dtd
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
fact.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
Now when using this android we are getting the exception : ParserConfigurationException
As far as I understood android technically is not supporting it as you can see in the source for Android 9 : http://androidxref.com/9.0.0_r3/xref/libcore/luni/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderFactoryImpl.java
I have seen multiple queries regarding the same :
- documentbuilderfactory-cannot-setfeature-feature-secure-processing
- documentbuilderfactory-get-available-features
With all of this context, here are questions ?
- What is the recommend solution for enabling secure XML Parsing?
- Do we have to resort to a 3rd party solution?
- Or are XMLParsers that come by default with Android are already secure with features like external DTD processing disabled?