我用AppScan扫描了Python源代码,它说代码包含潜在的漏洞(XML注入)。例如:
import xml.dom.minidom
...
dom = xml.dom.minidom.parse(filename)
...
document = xml.dom.minidom.parseString(xmlStr)
...
我安装了defusedxml并用parse/parseString替换了所有使用标准pythonxml包的parsingdefusedxml.minidom&安培;defusedxml.cElementTree公司名称:
^{pr2}$这些漏洞已从扫描报告中消失。但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?在
ElementTree不受恶意构造数据的保护。见list of vulnerabilities。考虑改用defusedxml。在
相关问题 更多 >
编程相关推荐