LangGrinch: The Critical Flaw Exposing Secrets in LangChain Core

By Ashish S
LangGrinch: The Critical Flaw Exposing Secrets in LangChain Core

Introduction

In the rapidly evolving world of artificial intelligence, frameworks like LangChain have become essential tools for developers building applications powered by large language models. However, a recently disclosed vulnerability has sent shockwaves through the community. Dubbed LangGrinch by its discoverers, CVE-2025-68664 represents a serious security risk that could allow attackers to extract sensitive secrets, manipulate application behavior, and potentially execute arbitrary code. This flaw, rated as critical with a CVSS score of 9.3, highlights the growing challenges in securing AI-driven systems where untrusted inputs from models can lead to unexpected dangers. As AI adoption surges, understanding and addressing such vulnerabilities is crucial for maintaining trust in these technologies.

Understanding the Vulnerability

At its core, CVE-2025-68664 is a serialization injection issue within the LangChain Core library. The problem lies in the dumps() and dumpd() functions, which are responsible for serializing data structures into a format that can be stored or transmitted. These functions fail to properly escape dictionaries containing the reserved 'lc' key when that data comes from user-controlled sources. The 'lc' key is an internal marker used by LangChain to denote its own objects during serialization. When unescaped, attacker-crafted data mimicking this structure gets treated as legitimate LangChain objects upon deserialization using load() or loads().

This deserialization of untrusted data falls under CWE-502, a well-known weakness category that has plagued software for years. In LangChain's case, it opens the door to injecting arbitrary objects, which can have side effects ranging from data leaks to network interactions. The vulnerability affects common workflows where serialization and deserialization occur, such as event streaming, logging, caching, and message history management. Developers using LangChain for agentic AI applications - those where models interact autonomously - are particularly at risk, as these systems often process dynamic, model-generated content without sufficient sanitization.

The issue was discovered by security researchers, including Yarden Porat from Cyata, and was publicly disclosed in late December 2025. It impacts a wide range of versions, specifically all releases prior to 0.3.81 and those from 0.4.0.dev0 up to but not including 1.2.5. Given LangChain's popularity, with hundreds of millions of downloads, the potential exposure is vast, affecting everything from prototype chatbots to production-grade AI pipelines in enterprises.

Technical Breakdown

To grasp the mechanics, consider how LangChain handles data serialization. When an object is passed to dumps(), it checks for the 'lc' key to determine if it's an internal construct. If present, the associated data is serialized in a way that preserves its type and properties for later reconstruction. However, if an attacker injects a dictionary with 'lc' into fields like additional_kwargs or response_metadata - which are often populated by LLM outputs - this malicious structure slips through unescaped.

Upon deserialization, the load() function interprets this as a trusted LangChain object. For instance, an attacker could craft a structure like {'lc': 1, 'type': 'secret', 'id': ['OPENAI_API_KEY']}. If secrets_from_env is enabled (which was the default in vulnerable versions), this would resolve to the actual environment variable, leaking API keys or other credentials. More advanced injections might instantiate classes from allowed namespaces, such as langchain_core or langchain_aws, triggering side effects on creation.

The advisory outlines at least 12 vulnerable flows within LangChain. These include astream_events (version 'v1'), Runnable.astream_log(), and components like RunnableWithMessageHistory or InMemoryVectorStore.load(). In each case, user-influenced data - potentially tainted by prompt injection - gets serialized and later deserialized, amplifying the attack surface. Prompt injection, where an attacker crafts inputs to manipulate LLM responses, serves as the primary entry point, turning seemingly benign model outputs into vectors for exploitation.

Furthermore, the allowlist mechanism, intended to restrict deserializable classes, proves insufficient. While it limits instantiation to approved modules, some classes within those modules - like ChatBedrockConverse - perform network calls during initialization. An attacker could leverage this for blind server-side request forgery (SSRF), directing requests to external servers and exfiltrating data through headers populated with leaked secrets.

Exploitation Scenarios

Exploitation typically begins with prompt injection. An attacker submits a carefully worded query to an LLM-integrated application, coaxing the model to include the malicious 'lc' structure in its response metadata. This tainted data then flows into serialization routines. For example, in a streaming setup using astream_events, the response is serialized for logging or transmission, and upon deserialization elsewhere in the pipeline, the injection activates.

One common outcome is secret extraction. With secrets_from_env active, deserialized secrets resolve to environment variables, which could include database credentials, cloud access keys, or authentication tokens. In a demonstration scenario, injecting a secret-type object directly pulls values like OPENAI_API_KEY, exposing them to the attacker if the deserialized data is logged, returned, or processed insecurely.

Beyond leaks, instantiation of certain classes enables broader attacks. For instance, creating a PromptTemplate with a Jinja2 template could lead to arbitrary code execution if the template is rendered post-deserialization. While direct remote code execution (RCE) from loads() requires specific conditions, the potential exists in chained operations. SSRF is another vector: By instantiating network-capable classes, attackers can force outbound requests, potentially scanning internal networks or exfiltrating data to external endpoints.

In agentic systems, where AI agents chain tools and maintain state, the vulnerability persists across interactions. A single injected response could corrupt message history, leading to ongoing exploitation. The low complexity of the attack - network-based, no privileges required - makes it accessible to moderately skilled adversaries, with proof-of-concept exploits already discussed in security circles.

Impact on AI Applications

The ramifications extend far beyond individual applications. LangChain powers countless AI tools, from chat interfaces to complex agents in sectors like finance, healthcare, and e-commerce. A successful exploit could compromise sensitive user data, disrupt operations, or enable lateral movement within cloud environments. For organizations relying on LLMs for decision-making, leaked secrets might lead to account takeovers or data breaches, eroding user trust and inviting regulatory scrutiny.

On a broader scale, this vulnerability underscores the insecurities in the AI supply chain. Open-source frameworks like LangChain, while innovative, introduce risks when deployed at scale without rigorous security reviews. The default enabling of features like secrets_from_env exacerbates this, as developers might not anticipate the trust boundaries collapsing under prompt injection. With AI agents becoming more autonomous, such flaws could enable persistent threats, where compromised state leads to self-reinforcing attacks.

Industries heavily invested in AI, such as tech startups and enterprise software providers, face immediate pressure to audit and update. The global nature of LangChain's user base means impacts could span regions, from North American data centers to Asian development hubs, highlighting the need for coordinated vulnerability management in the AI ecosystem.

Mitigation and Patches

Addressing CVE-2025-68664 requires swift action. The primary fix is upgrading langchain-core to version 0.3.81 or 1.2.5, which introduces proper escaping for 'lc' keys during serialization. These patches also harden defaults: secrets_from_env is now disabled, reducing the risk of automatic secret resolution. Additionally, the allowlist for deserializable objects has been refined to minimize side effects.

Beyond upgrades, developers should treat all LLM outputs as untrusted. This means avoiding deserialization of data from fields like additional_kwargs, response_metadata, or tool outputs unless sanitized. Opt for safer alternatives, such as astream_events version 2, which avoids the vulnerable serialization paths. Conduct thorough code reviews for custom serialization usage and disable risky features in production.

Organizations should monitor dependencies, perhaps using tools like dependency scanners, to ensure ecosystem packages like langchain-community are also updated. Implementing runtime protections, such as input validation and least-privilege environments, can further mitigate risks. Finally, foster a security-first mindset in AI development, recognizing that model-generated content demands the same scrutiny as user inputs.

Conclusion

LangGrinch serves as a stark reminder of the vulnerabilities lurking in modern AI frameworks. As tools like LangChain democratize advanced AI capabilities, they also expand attack surfaces in unforeseen ways. By promptly patching and adopting secure practices, developers can safeguard their applications against such threats. In the end, securing AI isn't just about innovation - it's about building resilient systems that withstand the evolving landscape of cyber risks. The swift response from the LangChain team demonstrates the community's commitment, but ongoing vigilance is essential to prevent future Grinches from stealing the show.

Ashish S
Ashish S
Ashish is a Cybersecurity Student with over 2 years of experience in Cybersecurity Research, Bug Bounty hunting and programming.