title: XML/SVG Entity Expansion Bomb in Content Returned to an Agent
id: ATR-2026-02682
rule_version: 2
status: experimental
description: |
  Detects an entity-expansion bomb (billion laughs / quadratic blowup) inside XML, SVG, SBOM, XLSX-sheet or DTD content that a tool returns to an agent, or that an agent writes out. The decisive text is a DTD entity whose replacement value is a packed run of six or more entity references -- <!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;"> -- which is the only reason to write such a value: each layer multiplies, so a few hundred bytes expand to gigabytes and the parser, not the network, is what fails. Mined from CVE-2026-25128 (fast-xml-parser numeric-entity RangeError DoS). ATR already covers the OTHER half of the DTD attack surface -- external entities pulling file:// or http:// URLs (ATR-2026-00568 / ATR-2026-01608) -- because those rules key on a URI scheme. An expansion bomb contains no URI at all, so nothing in the corpus sees it. Benign DTDs are deliberately excluded: an entity table (<!ENTITY copyright "&#169; 2026 Example Ltd">) and a composite entity built from a handful of separated references (<!ENTITY footer "&company; &address; &phone;">) both fail the pattern, which requires SIX OR MORE references with no separator between them.
author: ATR Community (CVE sweep)
date: 2026/08/23
schema_version: '0.1'
detection_tier: pattern
maturity: test
severity: medium
references:
  cve:
    - CVE-2026-25128
  cwe:
    - CWE-776
    - CWE-400
  owasp_llm:
    - LLM10:2025
    - LLM05:2025
  owasp_agentic:
    - ASI06:2026
    - ASI03:2026
  mitre_attack:
    - T1499.004 - Application or System Exploitation
  mitre_atlas:
    - AML.T0029 - Denial of ML Service
  external:
    - https://nvd.nist.gov/vuln/detail/CVE-2026-25128
    - https://cwe.mitre.org/data/definitions/776.html
metadata_provenance:
  cve: human-reviewed
  cwe: human-reviewed
  owasp_llm: human-reviewed
  owasp_agentic: human-reviewed
  mitre_attack: human-reviewed
  mitre_atlas: human-reviewed
compliance:
  eu_ai_act:
    - article: '15'
      context: Article 15 (accuracy, robustness and cybersecurity) requires AI systems to be resilient against attempts to exploit vulnerabilities; this rule detects a parser resource-exhaustion payload arriving through tool output.
      strength: primary
    - article: '9'
      context: Article 9 (risk management system) requires identified risks to be treated; availability loss through untrusted-document parsing is treated here at runtime.
      strength: secondary
  nist_ai_rmf:
    - subcategory: MG.2.3
      context: Denial of service through untrusted document ingestion is an identified AI risk requiring an active runtime countermeasure; this rule implements it.
      strength: primary
    - subcategory: MS.2.6
      context: Measuring AI system resilience and safety under adversarial input; this rule instruments the resource-exhaustion case.
      strength: secondary
  iso_42001:
    - clause: '8.1'
      context: ISO/IEC 42001 Clause 8.1 (operational planning and control) is operationalised by screening ingested documents for expansion bombs before they reach a parser.
      strength: primary
    - clause: '8.3'
      context: ISO/IEC 42001 Clause 8.3 (AI risk treatment) is implemented by alerting on the bomb's entity-chain signature.
      strength: secondary
tags:
  category: tool-poisoning
  subcategory: xml-entity-expansion-bomb
  scan_target: agent
  confidence: high
  suppress_in_code_blocks: true
agent_source:
  type: mcp_exchange
  framework:
    - any
  provider:
    - any
detection:
  condition: any
  conditions:
    - field: content
      operator: regex
      value: (?i)<!entity\s+(?:%\s*)?[\w.-]{1,24}\s+["'][^"']{0,200}["']\s*>[\s\S]{0,200}<!entity\s+(?:%\s*)?[\w.-]{1,24}\s+["'](?:[&%][\w.-]{1,12};){6,}
      description: 'An entity declaration with a real body, followed within 200 characters by an entity whose value is a packed run of six or more references -- the two-layer structure a billion-laughs bomb needs. The chain is required because a single declaration cannot multiply: it expands once and stops.'
    - field: content
      operator: regex
      value: (?i)<!entity\s+(?:%\s*)?[\w.-]{1,24}\s+["'](?:[&%][\w.-]{1,12};){6,}[\s\S]{0,200}<!entity\s+(?:%\s*)?[\w.-]{1,24}\s+["'](?:[^&"'\r\n]|&[^#"'\r\n])
      description: The same two layers in the reverse declaration order, with the companion entity required to have a real body rather than a bare character reference (which is what a spacing or punctuation entity points at).
  false_positives:
    - 'FIXED in rule_version 2 -- A PACKED RUN OF CHARACTER ENTITIES IS NOT A BOMB. The pattern keyed on the run alone, so it fired on the ordinary publishing idiom of defining a fixed amount of space or punctuation: <!ENTITY sp6 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;">, an em-dash rule, a table-of-contents leader of &hellip;, an &emsp; gutter, and a DTD content model concatenating six short parameter entities. None of these can multiply -- they reference a character entity, expand exactly once and stop, which is the opposite of the property this rule exists to detect. The rule now requires the TWO-LAYER CHAIN a bomb needs: a companion entity declaration with a real body, either before the packed run or after it. Four measured FPs plus one DTD case are silent; all three true positives are unaffected.'
    - 'FIXED in rule_version 2 -- the same chain requirement removed the entire quotation class. Security writing quotes the ONE decisive line (<!ENTITY lol2 "&lol;&lol;...">) because that line is the explanation; it does not carry the companion declaration that makes the line dangerous. Measured: an unfenced CVE-2026-25128 write-up, the same write-up in Traditional Chinese, a hardening CHANGELOG and a fuzzer log line all fired before and are silent after. This was previously documented as a KNOWN RESIDUAL that suppress_in_code_blocks could only half-cover; it is now genuinely fixed rather than suppressed.'
    - 'RESIDUAL, MEASURED AND IRREDUCIBLE: a parser''s own regression fixture -- tests/fixtures/billion_laughs.xml, checked in so the test can assert the parser REFUSES it -- still fires. The file is a complete, working bomb; it is benign only because of where it lives, and no pattern over its bytes can know that.'
    - 'EVASION, STATED PLAINLY: the chain requirement gives a 200-character proximity window between the two declarations. A bomb that pads the gap wider than that, or that splits its layers across two documents, is no longer detected. Both declaration orders are covered, so simply reordering them does not evade.'
    - An ordinary entity table such as <!ENTITY copyright "&#169; 2026 Example Ltd"> or <!ENTITY amp "&#38;"> -- a single reference, not a packed run
    - A composite entity built from separated references, e.g. <!ENTITY footer "&company; &address; &phone;"> -- the spaces break the run and the count is below six
    - XHTML/DocBook DTD driver files that declare and immediately invoke parameter entities (%HTMLlat1;) -- each declaration holds a public identifier, not a reference run
    - 'A security article or advisory that prints the billion-laughs payload: the rule sets suppress_in_code_blocks, so a payload inside a markdown fence or inline backticks is not reported. KNOWN RESIDUAL: an article that pastes the payload as bare prose, with no fence and no backticks, will still match -- and so would a poisoned document, which is the reason the suppression is limited to code context rather than removed.'
response:
  actions:
    - alert
  message_template: |
    [ATR-2026-02682] Ingested XML/SVG/DTD content declares an entity whose value is a packed run of entity references -- an expansion bomb. Do not hand this document to an XML parser; expansion is multiplicative and will exhaust memory before any content is produced.
confidence: 82
