Skip to main content

CVE-2024-1455: Langchain XXE Billion Laughs DoS Vulnerability

CVE-2024-1455 is an XML External Entity flaw in Langchain that enables Billion Laughs attacks, causing severe resource exhaustion and denial of service. This article covers the technical details, affected versions, and mitigation.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-1455 Overview

CVE-2024-1455 is a denial-of-service vulnerability in the langchain-ai/langchain repository. The flaw resides in the XMLOutputParser component, which parses XML using Python's default xml.etree.ElementTree module. An attacker can submit a crafted XML document containing recursively nested entity definitions, known as a Billion Laughs Attack. The parser expands these nested entities, consuming excessive CPU and memory resources until the process becomes unresponsive. This is a variant of XML External Entity (XXE) exploitation categorized under [CWE-776] (Improper Restriction of Recursive Entity References in DTDs).

Critical Impact

Remote attackers can trigger denial of service against LangChain-based applications processing untrusted XML input, exhausting host CPU and memory.

Affected Products

  • langchain-ai/langchain (Python package langchain)
  • Applications using langchain_core.output_parsers.xml.XMLOutputParser
  • Downstream LLM pipelines that pass untrusted model output through the XML parser

Discovery Timeline

  • 2024-03-26 - CVE-2024-1455 published to NVD
  • 2024-03-26 - Vendor patch committed to langchain-ai/langchain (727d5023)
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-1455

Vulnerability Analysis

The vulnerability affects the XMLOutputParser class in libs/core/langchain_core/output_parsers/xml.py. The parser used Python's standard xml.etree.ElementTree module, which does not restrict entity expansion by default. When an application feeds untrusted XML into the parser, an adversary can define nested entity chains that expand exponentially. Each nesting level multiplies the referenced entity, so a small payload of a few kilobytes can expand into gigabytes of in-memory data. The parser blocks the worker thread while expanding entities, preventing the host from serving legitimate requests.

Root Cause

The underlying issue is the use of a non-hardened XML parser on attacker-controllable input. xml.etree.ElementTree does not enforce limits on entity recursion depth or expanded output size. LangChain accepted parser output from large language models and third-party sources without validation, creating a direct path from network input to the vulnerable parser.

Attack Vector

Exploitation requires an attacker to deliver a crafted XML document to any application surface that invokes XMLOutputParser. Common surfaces include chatbot prompts, retrieval pipelines that ingest external documents, and agents that consume tool output. No authentication is required when the surface is public. The attack complexity is elevated because the target must specifically route the input through the XML parser.

The upstream fix replaces the standard library parser with defusedxml, which rejects entity expansion attacks by default:

python
 import re
-import xml.etree.ElementTree as ET
 from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Union
+from xml.etree import ElementTree as ET
+from xml.etree.ElementTree import TreeBuilder
 
 from langchain_core.exceptions import OutputParserException
 from langchain_core.messages import BaseMessage

Source: langchain-ai/langchain commit 727d5023

The accompanying dependency change adds defusedxml to the core package:

text
 requests = "^2"
 packaging = "^23.2"
 jinja2 = { version = "^3", optional = true }
+defusedxml = "^0.7"

Source: libs/core/pyproject.toml patch

Detection Methods for CVE-2024-1455

Indicators of Compromise

  • Python processes running LangChain workloads showing sustained CPU saturation and rapid memory growth
  • Application logs referencing XMLOutputParser immediately before out-of-memory (OOM) kills or worker timeouts
  • Inbound requests containing XML payloads with nested <!ENTITY> declarations referencing other entities
  • Unusual restart cycles of LLM agents, gunicorn workers, or Kubernetes pods hosting LangChain services

Detection Strategies

  • Inspect HTTP request bodies at the reverse proxy or WAF for XML documents containing <!DOCTYPE and multiple <!ENTITY definitions.
  • Instrument the LangChain application to log the size of parser inputs and the elapsed time of XMLOutputParser.parse calls.
  • Alert on Python worker processes whose resident memory exceeds a baseline threshold within a short interval after receiving XML input.

Monitoring Recommendations

  • Track process-level CPU and memory metrics for containers running langchain and page on anomalous consumption spikes.
  • Aggregate application error logs for OutputParserException, OOM signals, and worker timeout events tied to XML processing.
  • Monitor dependency inventories to detect any regression that removes defusedxml from the environment.

How to Mitigate CVE-2024-1455

Immediate Actions Required

  • Upgrade langchain-core to the release containing commit 727d5023ce88e18e3074ef620a98137d26ff92a3, which switches XMLOutputParser to defusedxml.
  • Audit application code for direct use of xml.etree.ElementTree on untrusted input and replace it with defusedxml.ElementTree.
  • Enforce request size limits at the ingress layer to reject oversized XML payloads before they reach the parser.
  • Restart LangChain worker processes after upgrading to ensure the patched module is loaded.

Patch Information

The fix is delivered in pull request #19526, applied via commit 727d5023ce88e18e3074ef620a98137d26ff92a3 in the langchain-ai/langchain repository. The patch removes the standard-library XML import from libs/core/langchain_core/output_parsers/xml.py and adds defusedxml ^0.7 as a required dependency. See the GitHub commit overview and the Huntr bounty report for full technical context.

Workarounds

  • Wrap calls to XMLOutputParser with input validation that rejects documents containing <!DOCTYPE or <!ENTITY declarations.
  • Run LangChain workloads under strict memory cgroup limits so that entity expansion attempts are terminated before affecting neighboring services.
  • Isolate XML parsing in a separate worker or sandbox with a short execution timeout to bound the impact of malicious payloads.
bash
# Configuration example - upgrade langchain-core and pin defusedxml
pip install --upgrade "langchain-core" "defusedxml>=0.7"

# Verify the patched parser is in use
python -c "import defusedxml, langchain_core; print(defusedxml.__version__, langchain_core.__version__)"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.