CVE-2024-8309: Langchain community SQL Injection Vulnerability

LOW
Advisory Identifier: GHSA-45pg-36p6-83v9
CVSS 4.9
CWE-89 CWE-74
Published
Advisory Summary

CVE-2024-8309 is a LOW (CVSS 4.9) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Langchain community libraries in the PyPI ecosystem. The issue involves langchain sql injection vulnerability. Remediation is available by upgrading affected packages to version 0.2.19, 0.2.0.

CVE-2024-8309 at a Glance

CVE Identifier CVE-2024-8309
GHSA Identifier GHSA-45pg-36p6-83v9
Severity LOW
CVSS v3.1 Base Score 4.9
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Langchain community
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 4.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.0/AV:L/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L).

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2024-8309

To remediate this vulnerability, upgrade all affected Langchain community dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

langchain-community fixed: 0.2.19
pip install langchain-community>=0.2.19
langchain fixed: 0.2.0
pip install langchain>=0.2.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show langchain-community

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2024-8309, inspect your installed packages using pip:

pip show langchain-community

Analyze the terminal output to locate any version of Langchain community in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.2.19), your application is affected.

Note: The pip show langchain-community command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where 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. In Langchain community, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

A vulnerability in the GraphCypherQAChain class of langchain-ai/langchain version 0.2.5 allows for SQL injection through prompt injection. This vulnerability can lead to 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 create, update, or delete nodes and relationships without proper authorization, extract sensitive data, disrupt services, access data across different tenants, and compromise the integrity of the database.

CVE-2024-8309 Affected Langchain community Versions

2 component(s)
Fixed Versions:
0.2.190.2.0
Product / Package Ecosystem Affected Versions Fixed Version
langchain-community
PyPI
≥ 0.2.0
< 0.2.19
0.2.19
langchain
PyPI
< 0.2.0
0.2.0

References

Frequently Asked Questions

What is CVE-2024-8309?
CVE-2024-8309 is a security vulnerability in Langchain community involving Langchain SQL Injection vulnerability under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Langchain community versions are affected?
Affected versions include releases prior to 0.2.19, 0.2.0 across affected packages: langchain-community, langchain.
What version fixes CVE-2024-8309?
Upgrading to 0.2.19, 0.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is langchain-community affected?
Yes, langchain-community is affected in releases prior to 0.2.19. Upgrade your dependency to 0.2.19 or later.
Is langchain affected?
Yes, langchain is affected in releases prior to 0.2.0. Upgrade your dependency to 0.2.0 or later.
What is the CVSS score of CVE-2024-8309?
CVE-2024-8309 has a CVSS v3.1 base score of 4.9 (LOW) with vector string CVSS:3.0/AV:L/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L.
What CWE is associated with CVE-2024-8309?
CVE-2024-8309 is classified under 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.).
How can I check PyPI dependencies for CVE-2024-8309?
Run the dependency tree command: 'pip show langchain-community'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-45pg-36p6-83v9",
  "modified" : "2024-11-12T19:57:59Z",
  "published" : "2024-10-29T15:32:05Z",
  "aliases" : [ "CVE-2024-8309" ],
  "summary" : "Langchain SQL Injection vulnerability",
  "details" : "A vulnerability in the GraphCypherQAChain class of langchain-ai/langchain version 0.2.5 allows for SQL injection through prompt injection. This vulnerability can lead to 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 create, update, or delete nodes and relationships without proper authorization, extract sensitive data, disrupt services, access data across different tenants, and compromise the integrity of the database.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.0/AV:L/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "langchain-community"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.2.0"
      }, {
        "fixed" : "0.2.19"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "langchain"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-8309"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/langchain-ai/langchain/commit/64c317eba05fbac0c6a6fc5aa192bc0d7130972e"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/langchain-ai/langchain/commit/c2a3021bb0c5f54649d380b42a0684ca5778c255"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/langchain-ai/langchain"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/langchain/PYSEC-2024-115.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://huntr.com/bounties/8f4ad910-7fdc-4089-8f0a-b5df5f32e7c5"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-74", "CWE-89" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-29T19:54:15Z",
    "nvd_published_at" : "2024-10-29T13:15:10Z"
  }
}