CVE-2025-68664: LangChain Serialization Injection Vulnerability Allows Secret Extraction
Summary
CVE-2025-68664: LangChain serialization injection vulnerability enables secret extraction in dumps/loads APIs. Affects langchain-core across 2 version ranges.
< 0.3.81
>= 1.0.0, < 1.2.5
Fixed in 0.3.81 or 1.2.5, depending on the release line you run. How to fix ↓
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.
No signup required · Results in about 60 seconds
Background
LangChain is an open-source framework designed for building applications that utilize language models. It provides functionalities for serialization and deserialization of objects, enabling developers to manage complex data structures easily. However, a critical vulnerability has been identified in its serialization methods, specifically in the dumps() and dumpd() functions, which fail to properly escape user-controlled data containing specific keys, leading to potential security risks.
Vulnerability Detail
A serialization injection vulnerability exists in LangChain's dumps() and dumpd() functions. These functions do not escape dictionaries with 'lc' keys when serializing free-form dictionaries. As a result, user-controlled data containing this key structure is treated as legitimate LangChain objects during deserialization. This vulnerability allows attackers to inject malicious structures through user data, enabling them to extract sensitive information such as environment variable secrets or instantiate classes with controlled parameters, potentially triggering harmful side effects.
How To Fix
Latest published version: 1.7.0 as of 22 Oct 2026
pip install --upgrade "langchain-core==1.7.0"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 0.3.810.3.81pip install --upgrade "langchain-core==0.3.81" -
>= 1.0.0, < 1.2.51.2.5pip install --upgrade "langchain-core==1.2.5"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If immediate patching is not feasible, consider implementing input validation to sanitize user-controlled data before serialization. For example, avoid using user data directly in serialization functions or implement a custom serialization method that escapes or filters out 'lc' keys. Here is a simple code snippet to demonstrate input validation:
def safe_dumps(data):
if isinstance(data, dict) and 'lc' in data:
raise ValueError('Invalid data structure: contains forbidden key')
return dumps(data)
Use safe_dumps() instead of dumps() to prevent serialization of unsafe data.
Conclusion
The LangChain serialization injection vulnerability (CVE-2025-68664) poses significant risks to applications using the affected serialization methods. It is crucial for developers to update to the latest patched version of the package and implement necessary security measures to protect against potential exploits.
See every vulnerability recorded for langchain-core →
FAQ
The CVSS score of this vulnerability is 9.3, indicating a critical level of severity.
You can use Vulert to monitor and alert for open-source vulnerabilities in your software. Visit the Vulert playground at Vulert Scanner to check if your application is affected without requiring signup.
Attackers can exploit this vulnerability to extract sensitive information, such as environment variable secrets, or execute arbitrary code by instantiating classes with controlled parameters.
Implement input validation to sanitize user-controlled data before serialization as a temporary workaround until you can apply the patch.
The patch introduces escaping for user-controlled data, restricts deserialization to an allowlist of classes, changes the default setting for loading secrets from environment variables, and blocks Jinja2 templates by default.
References
Related vulnerabilities
Recent vulnerabilities recorded for langchain-core.