Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB
CVE-2024-10940 Overview
CVE-2024-10940 is an arbitrary file read vulnerability in the langchain-core Python package. The flaw resides in langchain_core.prompts.ImagePromptTemplate and the parent ChatPromptTemplate, which accept user-controlled input variables that resolve to local file paths. When the server loads an image for base64 encoding, an attacker can supply any path on the host file system. If the resulting prompt output is returned to the user or passed through to a downstream model response, sensitive file contents are exposed. The issue is tracked under CWE-497 and affects LangChain applications that expose prompt templates to untrusted inputs.
Critical Impact
Unauthenticated attackers can read arbitrary files from the server file system through crafted prompt template inputs, leading to disclosure of configuration files, credentials, and application source code.
Affected Products
- langchain-core versions >=0.1.17,<0.1.53
- langchain-core versions >=0.2.0,<0.2.43
- langchain-core versions >=0.3.0,<0.3.15
Discovery Timeline
- 2025-03-20 - CVE-2024-10940 published to NVD
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2024-10940
Vulnerability Analysis
The vulnerability lives in langchain_core/utils/image.py, which exposed two helpers: encode_image(image_path) and image_to_data_url(image_path). Both functions call open(image_path, "rb") directly on a caller-supplied string. ImagePromptTemplate consumed these helpers to turn a template variable into a base64 data URL embedded in a prompt.
Because the template engine substitutes user-controlled variables into image_path, any input that reaches the template at runtime becomes a local file read. There is no allow-list, scheme check, or path containment validation. When an application forwards the rendered prompt back to the client or includes it in a model response, the base64 payload leaks file contents verbatim.
Root Cause
The root cause is missing input validation on the image_path parameter inside ImagePromptTemplate. The template system treats file paths as a trusted sink even though variable substitution is performed with untrusted data. Information exposure through sensitive system data falls under CWE-497.
Attack Vector
An attacker submits a prompt variable such as /etc/passwd, /proc/self/environ, or C:\Users\Administrator\.aws\credentials to any endpoint that renders an ImagePromptTemplate or a ChatPromptTemplate containing one. The server opens the file, encodes it, and either returns the data URL in the prompt output or forwards it to an LLM whose response echoes the content.
# Patched code in libs/core/langchain_core/utils/image.py
# The vulnerable helpers were removed entirely
-import base64
-import mimetypes
+from typing import Any
-def encode_image(image_path: str) -> str:
- """Get base64 string from image URI."""
- with open(image_path, "rb") as image_file:
- return base64.b64encode(image_file.read()).decode("utf-8")
-
-
-def image_to_data_url(image_path: str) -> str:
- """Get data URL from image URI."""
- encoding = encode_image(image_path)
- mime_type = mimetypes.guess_type(image_path)[0]
- return f"data:{mime_type};base64,{encoding}"
Source: LangChain commit c1e7423
Detection Methods for CVE-2024-10940
Indicators of Compromise
- Prompt inputs containing absolute paths such as /etc/passwd, /root/.ssh/id_rsa, /proc/self/environ, or Windows paths like C:\Windows\win.ini.
- Application logs showing ImagePromptTemplate resolving variables that do not match expected image file extensions.
- Outbound responses or model completions containing large base64 blobs that decode to plain text configuration or credential material.
Detection Strategies
- Inventory Python dependencies for langchain-core versions listed as affected and flag any application that instantiates ImagePromptTemplate or renders chat templates with user input.
- Review request payloads for template variables resolving to paths outside the expected image directory.
- Correlate file-open events on the application host against processes running the LangChain runtime to find reads of sensitive paths.
Monitoring Recommendations
- Enable file access auditing on sensitive directories (/etc, /root, cloud credential paths) for the service account running LangChain workloads.
- Alert on HTTP responses that contain base64-encoded data larger than a defined threshold on endpoints that are not expected to return media.
- Capture and retain prompt and completion logs in a centralized data lake to support retrospective hunting after disclosure of new prompt-injection techniques.
How to Mitigate CVE-2024-10940
Immediate Actions Required
- Upgrade langchain-core to 0.1.53, 0.2.43, 0.3.15, or later, which removes the vulnerable image-loading helpers.
- Audit application code for any direct use of encode_image or image_to_data_url and replace it with explicit, validated media handling.
- Rotate any credentials, API keys, or secrets stored in paths that may have been read through an exposed template endpoint.
Patch Information
The fix landed in LangChain commit c1e7423, which deletes encode_image and image_to_data_url from langchain_core/utils/image.py and removes the image_utils import from ImagePromptTemplate. Additional context is available in the Huntr bounty report.
Workarounds
- If immediate upgrade is not possible, remove ImagePromptTemplate usage from any template that accepts untrusted input.
- Validate template variables against an allow-list of filenames inside a dedicated, non-sensitive image directory before rendering.
- Run the LangChain process under a least-privileged user with no read access to secrets, SSH keys, or cloud credential files.
# Upgrade to a patched release
pip install --upgrade "langchain-core>=0.3.15"
# Or pin to the fixed version on the 0.2.x branch
pip install "langchain-core==0.2.43"
# Or pin to the fixed version on the 0.1.x branch
pip install "langchain-core==0.1.53"
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB

