CVE-2024-8309: Langchain SQL Injection Vulnerability

langchain Updated 07 Jul 2026

Summary

07/07/2026
Yes i
Medium
4.9

CVE-2024-8309: Langchain SQL Injection vulnerability. Affects langchain versions < 0.2.0. Fixed in 0.2.0. How to fix ↓

Also tracked for

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.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

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 →

Share this vulnerability

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.

Related vulnerabilities

Recent vulnerabilities recorded for langchain.

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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback