ArticleslgStudy

computer science

Billion laughs attack

Billion laughs attack is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Billion laughs attack rather than just read about it. In short: In computer security, a billion laughs attack is a type of denial-of-service attack (DoS attack) which is aimed at parsers of XML documents. It is also referred to as an XML bomb or as an exponential entity expansion attack.

Key takeaways

  • Billion laughs attack belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Billion laughs attack to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Billion laughs attack from memory before moving on to harder problems.

Reference excerpt

In computer security, a billion laughs attack is a type of denial-of-service attack (DoS attack) which is aimed at parsers of XML documents. It is also referred to as an XML bomb or as an exponential entity expansion attack.

Details The example attack consists of defining 10 entities, each defined as consisting of 10 of the previous entity, with the document consisting of a single instance of the largest entity, which expands to one billion copies of the first entity. Versions with larger amount of entries also exist. In the most frequently cited example, the first entity is the string "lol", hence the name "billion laughs". At the time this vulnerability was first reported, the computer memory used by a billion instances of the string "lol" would likely exceed that available to the process parsing the XML. While the original form of the attack was aimed specifically at XML parsers, the term may be applicable to similar subjects as well. The problem was first reported as early as 2002, but began to be widely addressed in 2008. Defenses against this kind of attack include capping the memory allocated in an individual parser if loss of the document is acceptable, or treating entities symbolically and expanding them lazily only when (and to the extent) their content is to be used.

Code example

When an XML parser loads this document, it sees that it includes one root element, "lolz", that contains the text "&lol9;". However, "&lol9;" is a defined entity that expands to a string containing ten "&lol8;" strings. Each "&lol8;" string is a defined entity that expands to ten "&lol7;" strings, and so on. After all the entity expansions have been processed, this small (< 1 KB) block of XML will actually contain 109 = a billion "lol"s, taking up almost 3 gigabytes of memory.

Variations The billion laughs attack described above can take an exponential amount of space or time. The quadratic blowup variation causes quadratic growth in resource requirements by simply repeating a large entity over and over again, to avoid countermeasures that detect heavily nested entities. (See computational complexity theory for comparisons of different growth classes.) A "billion laughs" attack could exist for any file format that can contain macro expansions, for example this YAML bomb:

This crashed earlier versions of Go because the Go YAML processor (contrary to the YAML spec) expands references as if they were macros. The Go YAML processor was modified to fail parsing if the result object becomes too large. Enterprise software like Kubernetes has been affected by this attack through its YAML parser. For this reason, either a parser with intentionally limited capabilities is preferred (like StrictYAML) or file formats that do not allow references are often preferred for data arriving from untrusted sources.

See also

Document type definition – Set of markup declarations for SGML-family markup language (DTD), a template for validating XML files Fork bomb – Type of denial-of-service software attack, a similar method to exhaust a system's resources through recursion Recursion – Process of repeating items in a self-similar way XML external entity attack – Type of attack on computer systems Zip bomb – Malicious archive file designed to disrupt the program or system reading it, a similar attack utilizing zip archives

References

Worked examples

Example 1 — a first encounter with Billion laughs attack

Start with the simplest possible case. Write down what Billion laughs attack claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Billion laughs attack before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Billion laughs attack ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Billion laughs attack

In research
Billion laughs attack appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Billion laughs attack in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Billion laughs attack is common in secondary-school and first-year university syllabi. It links to neighbouring topics Algorithmic complexity attacks, Denial-of-service attacks, XML, so understanding it makes those chapters shorter.
In everyday life
Look for Billion laughs attack outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Billion laughs attack” →

How to study Billion laughs attack in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Billion laughs attack means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Billion laughs attack out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Billion laughs attack in simple terms?

In computer security, a billion laughs attack is a type of denial-of-service attack (DoS attack) which is aimed at parsers of XML documents. It is also referred to as an XML bomb or as an exponential entity expansion attack.

Why does Billion laughs attack matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Billion laughs attack?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Billion laughs attack.

Tags

  • Algorithmic complexity attacks
  • Denial-of-service attacks
  • XML

Keep exploring