AgentbeamBeta
AI agent vulnerability · LangChain

CVE-2024-3571: langchain vulnerable to path traversal

mediumCVSS 3.0 6.5GHSA-rgp8-pm28-3759

LangChain before 0.0.353 has a path traversal in LocalFileStore. Keys passed to mset and mget are not kept inside the store's root directory, so an attacker who controls a key can read or write files anywhere the process can reach, which can lead to code execution. Upgrade to langchain 0.0.353.

Published Apr 16, 2024 · Analysis Nov 18, 2026

What an attacker can do

LocalFileStore maps each key to a file under a root directory. Its mset and mget methods built the path from the key without checking that the result stayed inside the root. A key such as ../etc/passwd, or an absolute path such as /etc, escapes the root. That gives read access with mget and write access with mset.

The attacker needs to reach an application that passes untrusted input into the keys of a LocalFileStore, for example a cache or document store keyed by user input. The CVSS 3.0 vector (AV:N/AC:L/PR:L/UI:N) assumes low privileges on such an app and rates only confidentiality as high, but the advisory warns the write path can lead to remote code execution, for example by overwriting a script or config that the host later runs. The risk depends on your application's use of the store.

Who is affected

The pip package langchain is affected before 0.0.353, in applications that use LocalFileStore with keys that come from untrusted input. Applications that use only fixed, trusted keys are not exposed through this flaw.

Check the version:

pip show langchain

Search your code for LocalFileStore to see whether it is used.

langchain

Ecosystem
PyPI
Affected
< 0.0.353
Fixed in
0.0.353
Check
pip show langchain

How to fix it

Upgrade to langchain 0.0.353:

pip install --upgrade langchain==0.0.353

The fix commit aad3d8bd makes the root absolute and resolves each key with _get_full_path. It checks with os.path.commonpath that the path is still under the root and raises InvalidKeyException if not. Tests cover mset, mget and yield_keys. Separately, never pass user input straight in as a store key.

How to tell if you were hit

Search application logs for InvalidKeyException after the upgrade, which shows attempted escapes. Before the upgrade, review keys that were passed to LocalFileStore for ../ sequences or leading slashes, and check for unexpected files or modified files outside the store directory, such as in the application or home directory.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

langchain-ai/langchain is vulnerable to path traversal due to improper limitation of a pathname to a restricted directory ('Path Traversal') in its LocalFileStore functionality. An attacker can leverage this vulnerability to read or write files anywhere on the filesystem, potentially leading to information disclosure or remote code execution. The issue lies in the handling of file paths in the mset and mget methods, where user-supplied input is not adequately sanitized, allowing directory traversal sequences to reach unintended directories.

Questions

Which LangChain version fixes CVE-2024-3571?

LangChain 0.0.353 fixes it. Every version before 0.0.353 is affected, so upgrade the package.

Am I at risk if I do not use LocalFileStore?

No. The flaw is in LocalFileStore's mset and mget handling of keys.

Can it lead to code execution?

The advisory says arbitrary file write can lead to remote code execution, for example by changing a file the host later runs. The direct effect is file read and write.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More LangChain vulnerabilities

All LangChain entries