CVE-2024-8309: Langchain SQL Injection Vulnerability
Summary
CVE-2024-8309: Langchain SQL Injection vulnerability. Affects langchain versions < 0.2.0. Fixed in 0.2.0. How to fix ↓
Also tracked for
- langchain-community · PyPI
The same CVE-2024-8309 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Langchain is an open-source framework designed for building applications that utilize language models. It provides tools for integrating various data sources and enables developers to create complex workflows involving natural language processing. However, version 0.2.5 of Langchain has been identified to have a critical SQL injection vulnerability in the GraphCypherQAChain class, which can lead to severe security issues.
Vulnerability Detail
The vulnerability arises from improper handling of user inputs in the GraphCypherQAChain class, allowing attackers to perform SQL injection through prompt injection. This can result in unauthorized data manipulation, data exfiltration, denial of service (DoS) by deleting all data, breaches in multi-tenant security environments, and data integrity issues. Attackers can exploit this vulnerability to create, update, or delete nodes and relationships without proper authorization, extract sensitive data, disrupt services, and compromise the integrity of the database.
How To Fix
Latest published version: 1.4.7 as of 22 Oct 2026
pip install --upgrade "langchain==1.4.7"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
0.2.0
This is the first release that contains the fix.
pip install --upgrade "langchain==0.2.0"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, ensure that user inputs are properly sanitized and validated before processing them in the GraphCypherQAChain class. This can help mitigate the risk of SQL injection attacks until the package is updated. Example code for input validation could be:
import re
def validate_input(user_input):
if re.match('^[a-zA-Z0-9_]*$', user_input):
return True
return False
Conclusion
The SQL injection vulnerability in Langchain (CVE-2024-8309) poses significant risks to applications utilizing this framework. It is crucial for developers to update to the patched version and implement input validation to mitigate potential threats.
See every vulnerability recorded for langchain →
FAQ
CVE-2024-8309 is a vulnerability in the Langchain package that allows for SQL injection through prompt injection, potentially leading to unauthorized data manipulation.
Version 0.2.5 of Langchain is affected by this vulnerability. It is recommended to upgrade to version 0.2.0 or later.
The vulnerability can lead to unauthorized data manipulation, data exfiltration, denial of service, and breaches in multi-tenant security environments.
You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without requiring any signup.
Vulert is a tool that monitors and alerts in real-time for open-source vulnerabilities in software using just the Pipfile.lock, making it easy to stay informed about potential security issues.
References
Related vulnerabilities
Recent vulnerabilities recorded for langchain.