java - 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
我已经看到了多个关于相同的查询:
- documentbuilderfactory-cannot-setfeature-feature-secure-processing
- documentbuilderfactory-get-available-features
在所有这些背景下,这里有问题吗?
- 启用安全 XML 解析的推荐解决方案是什么?
- 我们必须求助于第三方解决方案吗?
- 或者,Android 默认附带的 XMLParsers 是否已经安全,并且禁用了外部 DTD 处理等功能?
解决方案
推荐阅读
- elm - Elm Html Bool 作为类型变量
- python - 正则表达式获取字母数字字符串之间的非字母数字字符串
- elasticsearch - Elasticsearch 如何计算 Completion Suggest 上的 _score?为什么我的分数不等重?
- gatsby - 在 Gatsby 配置文件中使用对象
- svg - SVGPanZoom 丢弃原来的 viewBox
- javascript - JavaScript 窗口调整大小事件很慢。如何优化窗口调整大小事件
- apache-kafka - 处理 kafka broker 完整磁盘空间
- mysql - 如何将mysql连接到Angular并在html中显示数据
- shopify - 如何在 Shopify 中实施内联 2heckout?
- html - 如何修复表格倒置