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

CVE-2023-32785: Langchain SQL Injection vulnerability

criticalCVSS 3.1 9.8GHSA-8h5w-f6q9-wg35

In LangChain before 0.0.247, SQLDatabaseChain sent LLM-generated SQL straight to the database, so a prompt injection could run arbitrary statements such as DROP TABLE. The code was removed from langchain in 0.0.247 and moved to langchain-experimental. Upgrade, and limit the chain's database permissions.

Published Oct 21, 2023 · Updated Oct 27, 2026 · Analysis Nov 2, 2026

What an attacker can do

The upstream issue titled "SQLDatabaseChain has SQL injection issue" describes the mechanism. The chain asks an LLM to write SQL for a user's question, then executes the result with no review step. Anyone who can influence the prompt can steer the SQL. The reporter's reproduction on the Chinook SQLite sample used a prompt like "Drop the employee table" and the table was dropped. Running the chain in an isolated container did not help, because the damage lands in the database.

The attacker needs only the ability to send text to an application that exposes the chain, often a chat or Q&A front end. No account on the database is required. The result is whatever the chain's database account is allowed to do: reading every table, changing or deleting data, and with some databases, reaching files or running commands. That is why the CVSS vector shows high confidentiality, integrity and availability impact.

The maintainers' conclusion was that the reliable protection is not text filtering but limiting the database permissions granted to the chain, so the database itself refuses commands like DROP TABLE.

Who is affected

The pip package langchain below 0.0.247, for applications that use SQLDatabaseChain or the SQL agent against a database. The same chain now lives in langchain-experimental, with security warnings, so the behavior remains if you use it there. Check what you have installed:

pip show langchain langchain-experimental

langchain

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

How to fix it

Upgrade to langchain 0.0.247 or later, where the code was removed (PR 8425). The chain moved to langchain-experimental with prominent security warnings (PR 9867). If you still use it, treat it as unsafe by default.

The maintainers' guidance: connect the chain with a least-privilege database user, read-only where possible and limited to the tables it needs, so the database blocks destructive statements. Keyword filters for DELETE or ALTER were proposed in the issue but were not the maintainers' answer.

How to tell if you were hit

Review database audit logs for statements issued by the chain's database user that are not simple SELECTs: DROP, DELETE, UPDATE, ALTER, queries on system tables and unusual joins. Check application logs for prompts containing instructions such as "drop" or "delete" or requests for other users' data. Check for missing tables or rows. If your agent platform records the SQL tool calls an AI agent makes, review those as well.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

In Langchain before 0.0.247, prompt injection allows execution of arbitrary code against the SQL service provided by the chain.

Credited to bertuxdeveloper.

Questions

Is langchain 0.0.247 or later safe from CVE-2023-32785?

The vulnerable code was removed from langchain in 0.0.247. If you installed the chain from langchain-experimental, it carries the same risk, so restrict database permissions.

Can a read-only database user fix it?

It removes the destructive statements, which is the maintainers' recommended protection. The chain can still read any table that user can read, so also limit the tables.

Does the attacker need credentials?

No. The CVSS vector shows no privileges. They only need a way to send text to an app using the chain.

Is it exploited in the wild?

No source I read says so, and the entry has no CISA KEV data.

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