Pattern: Use of insecure xml.dom.expatbuilder
module
Issue: -
This module is not secure against maliciously constructed data. Use defusedxml
package instead.
The results of an attack on a vulnerable XML library can be fairly dramatic. With just a few hundred Bytes of XML data an attacker can occupy several Gigabytes of memory within seconds. An attacker can also keep CPUs busy for a long time with a small to medium size request. Under some circumstances it is even possible to access local files on your server, to circumvent a firewall, or to abuse services to rebound attacks to third parties.
This rule checks for the following calls:
xml.dom.expatbuilder.parse
xml.dom.expatbuilder.parseString
Example of insecure code:
import xml.dom.expatbuilder as bad
bad.parse('filethatdoesntexist.xml')
xmlString = "<note>malicious code</note>"
bad.parseString(xmlString)
Example of secure code:
import defusedxml.expatbuilder as good
good.parse('filethatdoesntexist.xml')
xmlString = "<note>malicious code</note>"
good.parseString(xmlString)