XML hash collision DoS vulnerability in Python's xml.etree module
The xml.etree module in Python's standard library did not set a random hash seed for expat's internal hash table, leaving it with low entropy. An attacker could send crafted XML with a large DTD to cause hash collisions and mount a denial-of-service attack.
- Fixed in 10 days
- Disclosed after 40 days
Python's standard library uses libexpat to parse XML. Internally the expat library has a hash table implementation to efficiently store and lookup DTD elements like entities, elements, attributes, etc. Hash tables are potentially vulnerable to hash collision Denial-of-Service attacks, which turns a hash insert or lookup from O(1) best case scenario to O(n) worst case scenario. To mitigate hash collision attacks, expat introduced hash randomization.
Hash randomization depends on a good, unpredictable seed. The expat library either uses the operating systems CSPRNG or expects the application to set a good hash seed with XML_SetHashSalt() call. Python's standard library decided to go for XML_SetHashSalt(). Due to an oversight, XML_SetHashSalt() was only used in the pyexpat module, but not in the C-accelerator module _elementtree for xml.etree subpackage. As a consequence, the xml.etree parser used a low entropy and potentially predictable RNG on all platforms except Windows and very recent Linux versions with getrandom() syscall in libc. Since Python's autoconf system doesn't define XML_DEV_URANDOM, /dev/urandom wasn't used either. Further more expat's internal error check was disabled with XML_POOR_ENTROPY=1, too.
Bug report
Red Hat Product Security has assigned CVE-2018-14647 for this issue. The bug is tracked in upstream ticket https://bugs.python.org/issue34623 and will be fixed in the next releases of Python
Resources
- https://bugs.python.org/issue14234
- https://bugs.python.org/issue30947
- https://bugs.python.org/issue34623
- https://libexpat.github.io/doc/expat-internals-the-hash-tables/
Impact
An attack can abuse the vulnerability to mount a hash collision Denial-of-Service attack with carefully crafted XML data with a large DTD. Any server or client that parses XML, is potentially vulnerable.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the C-accelerator module _elementtree for xml.etree did not call XML_SetHashSalt() to set a random hash seed, and expat's entropy checks were disabled, so the hash table used a predictable seed.
Impact
An attacker could mount a hash collision denial-of-service attack against servers or clients that parse XML.
What the attacker needed
Target parses XML with xml.etree; attacker can supply XML input
The fix
The issue was to be fixed in the next releases of Python.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When software reads XML, it uses a hash table to quickly find names like entities and attributes. If an attacker can predict how those names map into the table, they can send many names that all land in the same slot, making lookups very slow. This report says Python's xml.etree module failed to randomise that mapping, so an attacker could craft XML that makes the parser slow down and deny service.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.