首页 > 解决方案 > DocumentBuilderFactory不允许禁用DTD时如何防止对Android的XXE攻击?

问题描述

在 Android 中使用DocumentBuilderFactory时,我们需要强制执行一些安全功能,以便可以安全地处理 XML。以下是我们尝试设置的标志

http://apache.org/xml/features/disallow-doctype-decl
http://apache.org/xml/features/nonvalidating/load-external-dtd

DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
fact.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

现在,当使用这个 android 时,我们得到了异常:ParserConfigurationException

据我了解,Android 技术上不支持它,正如您在 Android 9 的源代码中看到的那样: http ://androidxref.com/9.0.0_r3/xref/libcore/luni/src/main/java/org/apache/和谐/xml/parsers/DocumentBuilderFactoryImpl.java

我已经看到了多个关于相同的查询:

  1. documentbuilderfactory-cannot-setfeature-feature-secure-processing
  2. documentbuilderfactory-get-available-features

在所有这些背景下,这里有问题吗?

  1. 启用安全 XML 解析的推荐解决方案是什么?
  2. 我们必须求助于第三方解决方案吗?
  3. 或者,Android 默认附带的 XMLParsers 是否已经安全,并且禁用了外部 DTD 处理等功能?

标签: javaandroidxml-parsing

解决方案


推荐阅读