Understand XML attack vectors
mainXML parsers can be vulnerable to several types of attacks that exploit less common XML features like entity expansions and DTDs. Understanding these is critical for securing your application:
- Billion Laughs (Exponential Entity Expansion): Uses nested entities to expand a small XML file into gigabytes of memory, causing DoS via memory exhaustion and high CPU load.
- Quadratic Blowup: Repeats a single large entity many times. It avoids nested-depth countermeasures but still causes massive memory consumption.
- External Entity Expansion (Remote): Uses URIs (e.g.,
http://) in entity declarations to force the parser to download remote resources. This can be used for SSRF (Server-Side Request Forgery), bypassing firewalls, or DoS. - External Entity Expansion (Local File): Uses
file://or relative paths to force the parser to read local files (e.g.,/etc/passwd), potentially leaking sensitive configuration or system data. - DTD Retrieval: Some libraries automatically retrieve Document Type Definitions from remote or local locations, leading to similar risks as external entity expansion.