Security Audit of LangChain

X41 performed a source code audit of LangChain, a framework written in both Python and TypeScript for building agents and LLM-powered applications. The audit was sponsored and organized by the Open Source Technology Improvement Fund. The report is released now that the development team addressed the identified issues.

The source code in scope for this audit is hosted at the LangChain GitHub organization and spans across the following repositories and their respective commit hashes:

This audit covered the core repositories providing the basic functionality and datatypes of LangChain, as well as the community repository to provide a broader coverage of the LangChain ecosystem. Community integrations are heavily used, because they provide functionality to connect to external services, databases, vector stores and document loaders. As such, code in these repositories tends to be more exposed as it handles untrusted inputs directly.

Full report of the security audit: https://www.x41-dsec.de/static/reports/X41-OSTIF-LangChain-Public-Report-2026-05-08.pdf
OSTIF blog post: https://ostif.org/langchain-audit-complete/

LangChain

LangChain allows the development of LLM-powered applications. It allows developers to write tools that LLMs can use to work towards solutions. A tool can, for instance, perform an Internet search or do an audio transcription based on a user-supplied prompt. LangChain supports integrations for several other cloud and AI providers, such as AWS or OpenAI.

Audit Results

A total of 15 vulnerabilities were discovered during the source code audit of LangChain. Within the core repositories, 4 DoS vulnerabilities were discovered. 3 of these issues stem from uncontrolled recursion triggered by maliciously crafted input processed by custom parsers. The third DoS vulnerability arises from insufficient validation of externally supplied document URLs. An attacker who is able to provide the URL of a sufficiently large document (e.g., many-gigabyte file) could trigger excessive memory allocation, leading to memory exhaustion.

Additionally, two issues were identified in the LangChain library used to prevent SSRF. The library written in TypeScript does not perform DNS resolution on the provided hostname to verify that the target host is not located in the private network of the LangChain installation. This could allow attackers to supply a hostname that resolves to a private IP address, which would allow an SSRF attack to take place.

The SSRF library written in Python suffers from a TOCTOU vulnerability and is highlighted in the following code snippet.

validate_safe_url(url, allow_private=False, allow_http=True)
response = requests.get(url, timeout=timeout, **kwargs)

The validate_safe_url() function will initiate a DNS lookup to an attacker-controlled domain which may possess a single A record with time-to-live set to 0. The attacker-controlled DNS server will reply with a safe IP address to pass the checks. Since the time-to-live was set to 0, all DNS caches will re-retrieve the DNS reply on the next resolution issued by the requests library. Now the attacker-controlled DNS server may reply with a local IP address, bypassing the checks.

The other vulnerabilities documented in the report affect the community repositories. Most of them are SQL injection vulnerabilities affecting different DBMSs, such as ClickHouse, SurrealDB or PostgreSQL. An XXE injection was also found in a community plugin used to load Docugami documents.

Conclusion

The audit showed that the code of the LangChain core repositories is on a good security level compared to systems of similar size and complexity, as vulnerabilities found in these repositories are limited to incomplete protection against SSRF attacks, denial-of-service attacks, and resources exhaustion vulnerabilities.

As the community repositories contain many contributions, they contain several SQL injection vulnerabilities and poor interface design. They are not comparable to the core repositories in terms of quality and security.

Providing a consistent security best-practices guide, encouraging the contributors of the community repositories to write secure code, is expected to greatly improve the community repositories from a security standpoint. A basis for such a guide was proposed in the delivered audit report.