NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · LangChain

CVE-2024-7774: Langchain Path Traversal vulnerability

mediumCVSS 4.0 6.9 · 3.0 6.5GHSA-hc5w-c9f8-9cc4

The local file store in LangChain.js (the langchain npm package) before 0.2.19 does not check keys for path traversal. A key such as ../foo makes getFullPath point outside the store directory, so an attacker who controls keys can write, overwrite, read .txt files and delete files elsewhere. Upgrade langchain to 0.2.19.

Published Oct 29, 2024 · Updated Nov 1, 2024 · Analysis Nov 1, 2026

What an attacker can do

The file-system store in langchain/src/storage/file_system.ts builds the file path from a caller-supplied key in getFullPath. Before the fix it joined the key onto the root path without checking where the result landed. The advisory names three methods that expose it: setFileContent (write and overwrite), getParsedFile (read of .txt files) and mdelete (delete).

A key like ../foo or an absolute path steps out of the store directory. An application that passes user-influenced keys to this store, for example keys derived from a chat session or request parameter, lets the attacker write files anywhere the Node.js process can write, replace existing text files, read .txt files and delete files. The CVSS vectors show network access with no privileges and low confidentiality and integrity impact.

The store appends .txt to the key, which limits what an attacker can read. Overwrites and deletions are less constrained by that suffix. Applications that only use fixed, developer-chosen keys are not exposed. The impact grows when the Node.js process runs with broad filesystem rights.

Who is affected

langchain on npm, all versions below 0.2.19. The advisory was filed against 0.2.5. Only code that uses the LocalFileStore with keys an outsider can influence is exposed. Check the installed version:

npm ls langchain

Search your code for LocalFileStore and for calls that pass request data as a key.

langchain

Ecosystem
npm
Affected
< 0.2.19
Fixed in
0.2.19
Check
npm ls langchain

How to fix it

Upgrade to langchain 0.2.19:

npm install [email protected]

The fix, in pull request 6736, makes getFullPath resolve the path against the root and reject any result that falls outside it. It also rejects keys with characters outside letters, digits, underscore, dot, hyphen and slash. The commit adds a docs warning that the store can alter any text file in the provided directory and its subfolders, so point it at a directory that holds nothing else.

How to tell if you were hit

Check the store directory and parent directories for .txt files written or removed at unexpected times. Review application logs and request logs for keys that contain ../, a leading slash or a backslash. After the fix, bad keys raise errors such as Invalid characters in key. Seeing them tells you someone is probing. Audit the process's file writes outside the store directory.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

A path traversal vulnerability exists in the getFullPath method of langchain-ai/langchainjs version 0.2.5. This vulnerability allows attackers to save files anywhere in the filesystem, overwrite existing text files, read .txt files, and delete files. The vulnerability is exploited through the setFileContent, getParsedFile, and mdelete methods, which do not properly sanitize user input.

Credited to hinthornw.

Questions

Which methods are vulnerable in CVE-2024-7774?

setFileContent, getParsedFile and mdelete, all through getFullPath. They allow writing, reading .txt files and deleting files outside the store directory.

Which version fixes it?

langchain 0.2.19 on npm. The advisory was filed against 0.2.5, and anything below 0.2.19 is vulnerable.

Am I affected if I do not use the file store?

No. The flaw is in the local file-system store only. Other LangChain components are not part of this advisory.

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