在使用Python xml.dom.minidom XML注射

问题描述 投票:0回答:1

我使用AppScan扫描Python源代码和它说,该代码包含潜在漏洞(XML注入)。例如:

import xml.dom.minidom

...
dom = xml.dom.minidom.parse(filename)
...
document = xml.dom.minidom.parseString(xmlStr)
...

我安装了defusedxml和替换,其中使用标准的Python XML包解析/ parseString从defusedxml.minidom&defusedxml.cElementTree所有parsings:

import defusedxml.minidom

...
dom = defusedxml.minidom.parse(filename)
...
document = defusedxml.minidom.parseString(xmlStr)
...

这些漏洞是由扫描报告了。但仍然AppScan的通知我,从标准的XML包凡导入任何功能/类漏洞。从ElementTree的例子类修改/构建XML树:

from xml.etree.cElementTree import (  # vulnerability here
SubElement, Element, ElementTree)
import defusedxml.cElementTree as et
...
template = et.parse(template_filename)  # safe parsing

root = template.getroot()
email_list_el = root.find('emails').find('list')

for email_address in to_list:
    SubElement(email_list_el , 'string').text = email_address 
    root.find('subject')[0].text = subject
    root.find('body')[0].text = body
...

这可以被认为是一个漏洞,如果xml.dom.minidom仅用于编写XML?

python xml xml-parsing
1个回答
0
投票

ElementTree的不固定以防止恶意构造数据。见list of vulnerabilities。考虑使用defusedxml代替。

© www.soinside.com 2019 - 2024. All rights reserved.