XML外部实体(XXE)-外部参数实体和外部通用实体漏洞

时间:2019-01-21 06:23:46

标签: java xml security xmlsec xxe

为防止XXE攻击,我已禁用Java DocumentBuilderFactory建议的以下功能-https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet

        dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
        dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        dbf.setXIncludeAware(false);
        dbf.setExpandEntityReferences(false);

如果我不将外部通用实体和外部参数实体设置为false,是否存在任何漏洞?当我们将disallow-doctype-decl设置为true并将XIncludeAware设置为false时,将不允许扩展这些外部实体。

从上面的代码 dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);中删除这两行是否安全,还是必须保留它们。如果是强制性的,那么如果我们不将其设置为false,那么这些漏洞是什么?

即使我们将disallow-doctype设置为true,将XIncludeAware设置为false,将ExpandEntityReferences设置为false,也请提供特定于外部基因实型/参数实体的漏洞的示例。

1 个答案:

答案 0 :(得分:1)

保持它们不是强制。设置- name: Find the process shell: ps auxk +rss | tail register: process_name - name: Check system activity shell: sar -W register: sar_output - name: Run smem command: smem -s swap when: - ansible_facts['distribution'] == "RedHat" - ansible_facts['distribution_major_version'] == "7" register: smem_usage ignore_errors: yes - name: Save content to a file local_action: copy content="{{ item }}" dest="/tmp/swap_info.txt" with_items: - "{{ process_name }}" - "{{ sar_output }}" - "{{ smem_usage }}" 将防止XXE攻击,因为不受信任的XML中的任何内联disallow-doctype-decl声明都会导致解析器引发异常。

但是,由于DOCTYPEexternal-general-entitiestrue by default,所以我建议保持代码原样。如果这两行不存在,并且后来的维护者(天真地或错误地)删除了第一行,则代码将再次变得脆弱。将其他行明确显示在其中可以使维护人员在进行进一步修改时更有可能查找这些功能,并希望了解它们为什么存在。