Path Traversal Affecting langchain package, versions [,0.0.353)


0.0
medium

Snyk CVSS

    Attack Complexity Low
    Confidentiality High

    Threat Intelligence

    Exploit Maturity Proof of concept
    EPSS 0.04% (10th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-PYTHON-LANGCHAIN-6615703
  • published 16 Apr 2024
  • disclosed 16 Apr 2024
  • credit ninjafit

How to fix?

Upgrade langchain to version 0.0.353 or higher.

Overview

langchain is a Building applications with LLMs through composability

Affected versions of this package are vulnerable to Path Traversal due to improper limitation of a pathname to a restricted directory in its LocalFileStore functionality. An attacker can leverage this vulnerability to read or write files anywhere on the filesystem, potentially leading to information disclosure or remote code execution.

Note: The issue lies in the handling of file paths in the mset and mget methods, where user-supplied input is not adequately sanitized, allowing directory traversal sequences to reach unintended directories.

PoC


from langchain.storage import LocalFileStore

file_store = LocalFileStore("/home")

value = file_store.mget(["/etc/passwd"])

print(value)