CVE-2024-21513: Langchain experimental Langchain-experimental Vulnerable To Arbitrary Code Vulnerability

CRITICAL
Advisory Identifier: GHSA-cgcg-p68q-3w7v
CVSS 8.5
CWE-94
Published
Advisory Summary

CVE-2024-21513 is a CRITICAL (CVSS 8.5) langchain-experimental vulnerable to arbitrary code vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Langchain experimental libraries in the PyPI ecosystem. The issue involves langchain-experimental vulnerable to arbitrary code execution. Remediation is available by upgrading affected packages to version 0.0.21.

CVE-2024-21513 at a Glance

CVE Identifier CVE-2024-21513
GHSA Identifier GHSA-cgcg-p68q-3w7v
Severity CRITICAL
CVSS v3.1 Base Score 8.5
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Langchain experimental
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 8.5

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

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

How to Fix CVE-2024-21513

To remediate this vulnerability, upgrade all affected Langchain experimental 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-experimental fixed: 0.0.21
pip install langchain-experimental>=0.0.21
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-experimental

How to Check if You Are Affected

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

pip show langchain-experimental

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Langchain experimental, 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

Versions of the package langchain-experimental from 0.0.15 and before 0.0.21 are vulnerable to Arbitrary Code Execution when retrieving values from the database, the code will attempt to call 'eval' on all values. An attacker can exploit this vulnerability and execute arbitrary python code if they can control the input prompt and the server is configured with VectorSQLDatabaseChain. **Notes:** Impact on the Confidentiality, Integrity and Availability of the vulnerable component: Confidentiality: Code execution happens within the impacted component, in this case langchain-experimental, so all resources are necessarily accessible. Integrity: There is nothing protected by the impacted component inherently. Although anything returned from the component counts as 'information' for which the trustworthiness can be compromised. Availability: The loss of availability isn't caused by the attack itself, but it happens as a result during the attacker's post-exploitation steps. Impact on the Confidentiality, Integrity and Availability of the subsequent system: As a legitimate low-privileged user of the package (PR:L) the attacker does not have more access to data owned by the package as a result of this vulnerability than they did with normal usage (e.g. can query the DB). The unintended action that one can perform by breaking out of the app environment and exfiltrating files, making remote connections etc. happens during the post exploitation phase in the subsequent system - in this case, the OS. AT:P: An attacker needs to be able to influence the input prompt, whilst the server is configured with the VectorSQLDatabaseChain plugin.

CVE-2024-21513 Affected Langchain experimental Versions

1 component(s)
Fixed Versions:
0.0.21
Product / Package Ecosystem Affected Versions Fixed Version
langchain-experimental
PyPI
< 0.0.21
0.0.21

References

Frequently Asked Questions

What is CVE-2024-21513?
CVE-2024-21513 is a security vulnerability in Langchain experimental involving langchain-experimental vulnerable to Arbitrary Code Execution under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Langchain experimental versions are affected?
Affected versions include releases prior to 0.0.21 across affected packages: langchain-experimental.
What version fixes CVE-2024-21513?
Upgrading to 0.0.21 (or the latest patched release for your respective branch) resolves the vulnerability.
Is langchain-experimental affected?
Yes, langchain-experimental is affected in releases prior to 0.0.21. Upgrade your dependency to 0.0.21 or later.
What is the CVSS score of CVE-2024-21513?
CVE-2024-21513 has a CVSS v3.1 base score of 8.5 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2024-21513?
CVE-2024-21513 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check PyPI dependencies for CVE-2024-21513?
Run the dependency tree command: 'pip show langchain-experimental'. 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-cgcg-p68q-3w7v",
  "modified" : "2024-11-18T16:26:52Z",
  "published" : "2024-07-15T06:30:53Z",
  "aliases" : [ "CVE-2024-21513" ],
  "summary" : "langchain-experimental vulnerable to Arbitrary Code Execution",
  "details" : "Versions of the package langchain-experimental from 0.0.15 and before 0.0.21 are vulnerable to Arbitrary Code Execution when retrieving values from the database, the code will attempt to call 'eval' on all values. An attacker can exploit this vulnerability and execute arbitrary python code if they can control the input prompt and the server is configured with VectorSQLDatabaseChain.\n\n**Notes:**\n\nImpact on the Confidentiality, Integrity and Availability of the vulnerable component:\n\nConfidentiality: Code execution happens within the impacted component, in this case langchain-experimental, so all resources are necessarily accessible.\n\nIntegrity: There is nothing protected by the impacted component inherently. Although anything returned from the component counts as 'information' for which the trustworthiness can be compromised.\n\nAvailability: The loss of availability isn't caused by the attack itself, but it happens as a result during the attacker's post-exploitation steps.\n\n\nImpact on the Confidentiality, Integrity and Availability of the subsequent system:\n\nAs a legitimate low-privileged user of the package (PR:L) the attacker does not have more access to data owned by the package as a result of this vulnerability than they did with normal usage (e.g. can query the DB). The unintended action that one can perform by breaking out of the app environment and exfiltrating files, making remote connections etc. happens during the post exploitation phase in the subsequent system - in this case, the OS.\n\nAT:P: An attacker needs to be able to influence the input prompt, whilst the server is configured with the VectorSQLDatabaseChain plugin.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "langchain-experimental"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.0.21"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-21513"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/langchain-ai/langchain/commit/7b13292e3544b2f5f2bfb8a27a062ea2b0c34561"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/langchain-ai/langchain"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/langchain-ai/langchain/blob/672907bbbb7c38bf19787b78e4ffd7c8a9026fe4/libs/experimental/langchain_experimental/sql/vector_sql.py#L81"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/langchain-ai/langchain/blob/672907bbbb7c38bf19787b78e4ffd7c8a9026fe4/libs/experimental/langchain_experimental/sql/vector_sql.py%23L81"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/langchain-experimental/PYSEC-2024-62.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://security.snyk.io/vuln/SNYK-PYTHON-LANGCHAINEXPERIMENTAL-7278171"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-15T16:26:46Z",
    "nvd_published_at" : "2024-07-15T05:15:01Z"
  }
}