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

CVE-2024-21513: langchain-experimental vulnerable to Arbitrary Code Execution

criticalCVSS 4.0 9.0 · 3.1 8.5GHSA-cgcg-p68q-3w7v

langchain-experimental versions from 0.0.15 before 0.0.21 run Python `eval()` on every value that `VectorSQLDatabaseChain` reads back from the database. An attacker who can influence the prompt can get arbitrary Python executed on the server. Upgrade to langchain-experimental 0.0.21, or stop using `VectorSQLDatabaseChain`.

Published Jul 15, 2024 · Updated Nov 18, 2024 · Analysis Nov 1, 2026

What an attacker can do

VectorSQLDatabaseChain turns a natural-language question into a vector SQL query, runs it and returns the rows. In sql/vector_sql.py, the helper _try_eval called eval() on each column value in the result, and fell back to the raw value if that failed. Data that comes from the database is treated as code.

The attacker does not need to touch the database directly. A user who can only send prompts can steer the LLM to build a query that returns a string such as a Python expression, for instance through a SELECT of a literal. The chain then evaluates it in the application process. The advisory describes the requirement as being able to influence the input prompt while the server uses this chain, with a low-privileged account. Result: arbitrary Python as the application's user, so environment variables, API keys, files and network access are all reachable. The scope change in the CVSS 3.1 vector reflects the jump from the library to the host operating system.

Who is affected

Affected: langchain-experimental >= 0.0.15, < 0.0.21. The advisory data lists the range as every version below 0.0.21. Only applications that configure VectorSQLDatabaseChain and let untrusted users feed it prompts are exposed. Other chains in the package are not part of this advisory.

pip show langchain-experimental

Also search your code for VectorSQLDatabaseChain.

langchain-experimental

Ecosystem
PyPI
Affected
>= 0, < 0.0.21
Fixed in
0.0.21
Check
pip show langchain-experimental

How to fix it

Upgrade to langchain-experimental 0.0.21.

pip install --upgrade "langchain-experimental>=0.0.21"

The fix commit deletes _try_eval. get_result_from_sqldb now returns the raw result of db._execute(cmd, fetch="all"), so values come back as the database types them rather than as evaluated Python. Code that relied on the evaluated values may see different types. The advisory names no workaround beyond not using the chain with untrusted prompts.

How to tell if you were hit

Search your code and dependencies for VectorSQLDatabaseChain and for the old helper _try_eval. Review application logs for prompts or generated SQL that return Python-looking strings, such as __import__, os.system or subprocess. Look for unexpected child processes, outbound connections or new files from the process that serves the chain.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Versions of the package langchain-experimental from 0.0.15 and before 0.0.21 are vulnerable to Arbitrary Code Execution when retrieving values from the database, the code will attempt to call 'eval' on all values. An attacker can exploit this vulnerability and execute arbitrary python code if they can control the input prompt and the server is configured with VectorSQLDatabaseChain.

Notes:

Impact on the Confidentiality, Integrity and Availability of the vulnerable component:

Confidentiality: Code execution happens within the impacted component, in this case langchain-experimental, so all resources are necessarily accessible.

Integrity: There is nothing protected by the impacted component inherently. Although anything returned from the component counts as 'information' for which the trustworthiness can be compromised.

Availability: The loss of availability isn't caused by the attack itself, but it happens as a result during the attacker's post-exploitation steps.

Impact on the Confidentiality, Integrity and Availability of the subsequent system:

As a legitimate low-privileged user of the package (PR:L) the attacker does not have more access to data owned by the package as a result of this vulnerability than they did with normal usage (e.g. can query the DB). The unintended action that one can perform by breaking out of the app environment and exfiltrating files, making remote connections etc. happens during the post exploitation phase in the subsequent system - in this case, the OS.

AT:P: An attacker needs to be able to influence the input prompt, whilst the server is configured with the VectorSQLDatabaseChain plugin.

Questions

Does CVE-2024-21513 affect all of LangChain?

No. It affects the separate langchain-experimental package, and only when VectorSQLDatabaseChain is configured. The core langchain package is not the vulnerable one here.

Does the attacker need database access?

No. The advisory says control of the input prompt is enough, because the chain evaluates what the query returns.

What replaced eval in the fix?

Nothing. The commit removes _try_eval and returns raw query results.

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