CVE-2023-36189: LangChain SQLDatabaseChain: SQL injection, DB exfil

GHSA-7q94-qpjr-xpgm HIGH PoC AVAILABLE
Published July 6, 2023
CISO Take

Unauthenticated SQL injection in LangChain's SQLDatabaseChain allows full read access to any database the chain is connected to — no credentials or user interaction required. If your AI agents or LLM applications use LangChain's SQL tools, upgrade to 0.0.247+ immediately. This is a classic injection flaw in an AI-native component that often connects LLMs to sensitive internal databases.

What is the risk?

High severity (CVSS 7.5) with low attack complexity and no authentication barrier make this trivially exploitable if the LangChain application is network-exposed. EPSS of 0.002 and absence from CISA KEV suggest limited active exploitation, but the attack surface is significant: SQLDatabaseChain is a commonly used pattern in enterprise LLM deployments, often wired to production databases containing sensitive data. The real risk is that many LangChain deployments are internal-facing AI tools where SQL access is implicitly trusted.

What systems are affected?

Package Ecosystem Vulnerable Range Patched
LangChain pip No patch
139.8K OpenSSF 5.9 2.7K dependents Pushed 3d ago 24% patched ~156d to patch Full package profile →
LangChain pip >= 0, < 0.0.247 0.0.247
139.8K OpenSSF 5.9 2.7K dependents Pushed 3d ago 24% patched ~156d to patch Full package profile →

How severe is it?

CVSS 3.1
7.5 / 10
EPSS
0.9%
chance of exploitation in 30 days
Higher than 55% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Trivial
Exploitation Confidence
medium
Public PoC indexed (trickest/cve)
Composite signal derived from CISA KEV, VulnCheck KEV, CISA SSVC, EPSS, Metasploit, Exploit-DB, trickest/cve, Nuclei templates, and inthewild.io exploitation reports.

What is the attack surface?

AV AC PR UI S C I A
AV Network
AC Low
PR None
UI None
S Unchanged
C High
I None
A None

What should I do?

6 steps
  1. Patch: Upgrade langchain to >= 0.0.247. Reference PR #6051 for the fix.

  2. Audit: Inventory all internal services using langchain and validate version.

  3. Workaround (if unable to patch): Disable or remove SQLDatabaseChain usage; replace with parameterized query wrappers.

  4. Harden: Restrict the database user used by SQLDatabaseChain to minimum required tables and columns (principle of least privilege).

  5. Detect: Review database query logs for anomalous SQL patterns (UNION SELECT, subqueries, tautologies) originating from the LangChain service account.

  6. Network: Ensure LangChain endpoints are not exposed to untrusted networks.

What does CISA's SSVC say?

Decision Track
Exploitation none
Automatable Yes
Technical Impact partial

Source: CISA Vulnrichment (SSVC v2.0). Decision based on the CISA Coordinator decision tree.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 15 - Accuracy, robustness and cybersecurity
ISO 42001
A.6.2.6 - Information security of AI systems
NIST AI RMF
MANAGE-2.4 - Residual risks are monitored and managed
OWASP LLM Top 10
LLM06 - Sensitive Information Disclosure LLM07 - Insecure Plugin Design

Frequently Asked Questions

What is CVE-2023-36189?

Unauthenticated SQL injection in LangChain's SQLDatabaseChain allows full read access to any database the chain is connected to — no credentials or user interaction required. If your AI agents or LLM applications use LangChain's SQL tools, upgrade to 0.0.247+ immediately. This is a classic injection flaw in an AI-native component that often connects LLMs to sensitive internal databases.

Is CVE-2023-36189 actively exploited?

Proof-of-concept exploit code is publicly available for CVE-2023-36189, increasing the risk of exploitation.

How to fix CVE-2023-36189?

1. Patch: Upgrade langchain to >= 0.0.247. Reference PR #6051 for the fix. 2. Audit: Inventory all internal services using langchain and validate version. 3. Workaround (if unable to patch): Disable or remove SQLDatabaseChain usage; replace with parameterized query wrappers. 4. Harden: Restrict the database user used by SQLDatabaseChain to minimum required tables and columns (principle of least privilege). 5. Detect: Review database query logs for anomalous SQL patterns (UNION SELECT, subqueries, tautologies) originating from the LangChain service account. 6. Network: Ensure LangChain endpoints are not exposed to untrusted networks.

What systems are affected by CVE-2023-36189?

This vulnerability affects the following AI/ML architecture patterns: agent frameworks, text-to-SQL pipelines, LLM application backends, RAG pipelines.

What is the CVSS score for CVE-2023-36189?

CVE-2023-36189 has a CVSS v3.1 base score of 7.5 (HIGH). The EPSS exploitation probability is 0.91%.

What is the AI security impact?

Affected AI Architectures

agent frameworkstext-to-SQL pipelinesLLM application backendsRAG pipelines

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0025 Exfiltration via Cyber Means
AML.T0049 Exploit Public-Facing Application
AML.T0053 AI Agent Tool Invocation

Compliance Controls Affected

EU AI Act: Article 15
ISO 42001: A.6.2.6
NIST AI RMF: MANAGE-2.4
OWASP LLM Top 10: LLM06, LLM07

What are the technical details?

Original Advisory

SQL injection vulnerability in langchain before v0.0.247 allows a remote attacker to obtain sensitive information via the SQLDatabaseChain component.

Exploitation Scenario

An attacker targets an enterprise LLM assistant built on LangChain that accepts natural language questions and translates them to SQL queries via SQLDatabaseChain. By injecting a crafted query such as 'Show me orders' with appended SQL injection payloads, the attacker bypasses input validation and forces the chain to execute a UNION-based query against the underlying database. This allows enumeration of table schemas and full exfiltration of sensitive records — customer PII, financial data, or proprietary operational data — without any credentials. The AI layer acts as an unintentional SQL proxy, making detection harder since queries appear to originate from a trusted internal service account.

Weaknesses (CWE)

CWE-89 — Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'): The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.

  • [Architecture and Design] Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482]. For example, consider using persistence layers such as Hibernate or Enterprise Java Beans, which can provide significant protection against SQL injection if used properly.
  • [Architecture and Design] If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated. Process SQL queries using prepared statements, parameterized queries, or stored procedures. These features should accept parameters or variables and support strong typing. Do not dynamically construct and execute query strings within these features using "exec" or similar functionality, since this may re-introduce the possibility of SQL injection. [REF-867]

Source: MITRE CWE corpus.

CVSS Vector

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N

Timeline

Published
July 6, 2023
Last Modified
November 21, 2024
First Seen
July 6, 2023

Related Vulnerabilities