![](/img/trans.png)
[英]Reading XML file using xml.dom.minidom or elementtree - Python
[英]XML injections in Python using xml.dom.minidom
我使用AppScan掃描了Python源代碼,它說該代碼包含潛在的漏洞(XML注入)。 例如:
import xml.dom.minidom
...
dom = xml.dom.minidom.parse(filename)
...
document = xml.dom.minidom.parseString(xmlStr)
...
我安裝了defusedxml,並使用來自defusedxml.minidom和defusedxml.cElementTree的parse / parseString替換了使用標准Python xml包的所有解析:
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,可以將其視為漏洞嗎?
ElementTree不能防止惡意構建的數據。 請參閱漏洞列表 。 考慮改用defusedxml 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.