LangChain Text Splitters is vulnerable to XML External Entity (XXE) attacks due to unsafe XSLT parsing
The HTMLSectionSplitter class in langchain-text-splitters parses user-supplied XSLT stylesheets without hardening, so external entities and the XSLT document() function can resolve arbitrary URIs. An unauthenticated attacker could read local files or make outbound HTTP(S) requests from the LangChain process.
langchain-ai/langchain
Originally disclosed on huntr
The HTMLSectionSplitter class in langchain-text-splitters is vulnerable to XML External Entity (XXE) attacks due to unsafe XSLT parsing. This vulnerability arises because the class allows the use of arbitrary XSLT stylesheets, which are parsed using lxml.etree.parse() and lxml.etree.XSLT() without any hardening measures. In lxml versions up to 4.9.x, external entities are resolved by default, allowing attackers to read arbitrary local files or perform outbound HTTP(S) fetches. In lxml versions 5.0 and above, while entity expansion is disabled, the XSLT document() function can still read any URI unless XSLTAccessControl is applied. This vulnerability allows remote attackers to gain read-only access to any file the LangChain process can reach, including sensitive files such as SSH keys, environment files, source code, or cloud metadata. No authentication, special privileges, or user interaction are required, and the issue is exploitable in default deployments that enable custom XSLT.
From the GitHub Advisory Database (GHSA-m42m-m8cr-8m58, CC BY 4.0).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The HTMLSectionSplitter class parses arbitrary XSLT stylesheets with lxml without applying XSLTAccessControl or disabling external entity resolution.
Impact
An unauthenticated attacker could read any file the LangChain process can access, including SSH keys, environment files, source code, or cloud metadata, and could make outbound HTTP(S) requests.
What the attacker needed
Custom XSLT enabled (default); no authentication needed
The fix
The class should be fixed by applying XSLTAccessControl and disabling external entity resolution when parsing XSLT stylesheets.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
XSLT is a language for transforming XML documents. When a parser is not locked down, a malicious stylesheet can tell it to fetch other files or web addresses, which is called an XML External Entity (XXE) attack. Here the library accepted custom stylesheets and did not restrict what they could reach, so an attacker could read files on the server.
What is XXE?
An XML parser resolves entities the attacker defines, reading local files or making the server send requests.