WIPIVERSE All articles

Billion laughs attack

The Billion laughs attack is a type of denial‑of‑service (DoS) exploit that targets XML parsers by using recursive entity expansion. By defining a small number of entity references that expand exponentially when processed, an attacker can cause the parser to consume excessive CPU time and memory, potentially crashing the application or the host system.

Mechanism

  1. Entity Definition – In the XML document’s Document Type Definition (DTD), the attacker defines a series of entities that reference each other. A classic example is:

    <!DOCTYPE lolz [
    <!ENTITY lol "lol">
    <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
    <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
    <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
    <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
    <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
    <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
    <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
    <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
    <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
    ]>
    <lolz>&lol9;</lolz>
    

    The final entity &lol9; expands to 10¹⁰ (one billion) repetitions of the string “lol”.

  2. Resource Exhaustion – When a vulnerable XML parser resolves these entities, it must allocate memory for each expansion and perform the associated string processing. The exponential growth quickly overwhelms system resources.

  3. Denial of Service – The parser may become unresponsive, raise an out‑of‑memory exception, or cause the hosting application to terminate, thereby achieving a DoS condition.

Historical Context

  • The attack was first publicized in the early 2000s as part of security research on XML parsers. It gained prominence after being highlighted in security advisories and conference presentations concerning XML processing vulnerabilities.
  • It is also known as an XML Entity Expansion attack or Recursive Entity Expansion attack.

Affected Systems

  • Any application that parses XML with DTD processing enabled and does not impose limits on entity expansion can be vulnerable. This includes web services, configuration file readers, and messaging systems that accept XML payloads.
  • Vulnerabilities have been reported for a range of libraries and platforms, including older versions of Apache Xerces, Microsoft XML Core Services (MSXML), and various Java XML parsers.

Mitigation Strategies

Mitigation Description
Disable DTD processing Configure the parser to ignore DTDs entirely (XMLConstants.FEATURE_SECURE_PROCESSING, setFeature("http://apache.org/xml/features/disallow-doctype-decl", true), etc.).
Limit entity expansion Set explicit limits on the number and depth of entity expansions (e.g., maxEntityExpansionLimit).
Use a safe XML parser Prefer parsers that default to secure settings, such as the “secure processing” mode in Java’s DocumentBuilderFactory.
Validate input Apply schema validation that does not rely on DTDs, or whitelist acceptable XML structures before parsing.
Patch software Apply vendor‑issued updates that address known XML parsing vulnerabilities.

Detection

  • Monitoring for unusually large memory usage or CPU spikes during XML parsing can indicate an ongoing Billion laughs attack.
  • Logging parsing errors such as “entity expansion limit exceeded” helps distinguish intentional attacks from malformed inputs.

References in Security Literature

  • OWASP entry on “XML External Entity (XXE) Injection” discusses the Billion laughs attack as a sub‑category.
  • CVE entries (e.g., CVE‑2008‑5353) reference exploitation of recursive entity expansion in specific libraries.
  • NIST’s National Vulnerability Database (NVD) lists related vulnerabilities under the CWE‑777 “Denial of Service via Resource Exhaustion”.

The Billion laughs attack remains a canonical example of how seemingly innocuous input can be crafted to overload system resources, underscoring the importance of secure default configurations for XML processing components.

Browse

More topics to explore

    Browse all articles