NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · LangChain

CVE-2025-68665: LangChain serialization injection vulnerability enables secret extraction

highCVSS 3.1 8.6GHSA-r399-636x-v7f6

In LangChain JS, `Serializable.toJSON()` (and so `JSON.stringify()`) did not escape objects with an `lc` key inside kwargs. When `load()` later reads that output, injected data becomes a real LangChain object. Attackers can pull environment-variable secrets and build classes from the import maps. Fixed in @langchain/core 1.1.8 and 0.3.80, langchain 1.2.3 and 0.3.37.

Published Dec 23, 2025 · Updated Feb 20, 2026 · Analysis Nov 1, 2026

What an attacker can do

This is the JavaScript counterpart of the Python dumps() bug in langchain-core. The flaw is in Serializable.toJSON(). Free-form fields such as additional_kwargs, metadata and response_metadata could hold an object shaped like { lc: 1, type: "secret", id: ["ENV_VAR"] }. On load(), that object was treated as a LangChain secret reference and not as user data.

With secretsFromEnv on, which had no explicit default and acted as true, load() replaced the reference with the value of that environment variable. Injected constructor structures could also instantiate any class present in the import maps with attacker-chosen parameters. The core import map holds messages, prompts and documents, so the class reach is narrower than in Python. The advisory explains that classes must be in an import map to be built.

The usual route is prompt injection: an LLM response field is steered by a prompt, serialized in a streaming flow, then loaded. Apps that call JSON.stringify() on Serializable objects and load() the result, apps that load() untrusted data, and apps that use LangGraph checkpoints are named as exposed. The CVSS notes confidentiality impact only. No account is needed.

Who is affected

npm @langchain/core >= 1.0.0, < 1.1.8 and < 0.3.80. npm langchain >= 1.0.0, < 1.2.3 and < 0.3.37. Your app is exposed if it serializes untrusted data with these objects and reads it back with load(), or uses LangGraph checkpoints.

npm ls @langchain/core langchain

@langchain/core

Ecosystem
npm
Affected
>= 1.0.0, < 1.1.8
Fixed in
1.1.8
Check
npm ls @langchain/core

@langchain/core

Ecosystem
npm
Affected
< 0.3.80
Fixed in
0.3.80
Check
npm ls @langchain/core

langchain

Ecosystem
npm
Affected
>= 1.0.0, < 1.2.3
Fixed in
1.2.3
Check
npm ls langchain

langchain

Ecosystem
npm
Affected
< 0.3.37
Fixed in
0.3.37
Check
npm ls langchain

How to fix it

Upgrade to @langchain/core 1.1.8 (or 0.3.80) and langchain 1.2.3 (or 0.3.37):

npm install @langchain/[email protected] [email protected]

The patch wraps user objects with lc keys in __lc_escaped__ when serializing and treats them as plain data on load. It also makes secretsFromEnv default to false, so a missing secret now throws, and adds a maxDepth limit of 50. Pass secrets through secretsMap. Enable secretsFromEnv: true only for trusted data. Never fill importMap from user input.

How to tell if you were hit

Search stored messages, checkpoints, caches and logs for objects with "lc": 1 inside fields that should be plain text, and for "type": "secret" entries naming environment variables such as API keys. After upgrading, the key __lc_escaped__ in stored data shows the escape at work. Unusual outbound requests from a LangChain service may point to injected class instantiation. Treat any API keys in the process environment as exposed if you find a match, and rotate them.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Context

A serialization injection vulnerability exists in LangChain JS's toJSON() method (and subsequently when string-ifying objects using JSON.stringify(). The method did not escape objects with 'lc' keys when serializing free-form data in kwargs. The 'lc' key is used internally by LangChain to mark serialized objects. When user-controlled data contains this key structure, it is treated as a legitimate LangChain object during deserialization rather than plain user data.

Attack surface

The core vulnerability was in Serializable.toJSON(): this method failed to escape user-controlled objects containing 'lc' keys within kwargs (e.g., additional_kwargs, metadata, response_metadata). When this unescaped data was later deserialized via load(), the injected structures were treated as legitimate LangChain objects rather than plain user data.

This escaping bug enabled several attack vectors:

  1. Injection via user data: Malicious LangChain object structures could be injected through user-controlled fields like metadata, additional_kwargs, or response_metadata
  2. Secret extraction: Injected secret structures could extract environment variables when secretsFromEnv was enabled (which had no explicit default, effectively defaulting to true behavior)
  3. Class instantiation via import maps: Injected constructor structures could instantiate any class available in the provided import maps with attacker-controlled parameters

Note on import maps: Classes must be explicitly included in import maps to be instantiatable. The core import map includes standard types (messages, prompts, documents), and users can extend this via importMap and optionalImportsMap options. This architecture naturally limits the attack surface—an allowedObjects parameter is not necessary because users control which classes are available through the import maps they provide.

Security hardening: This patch fixes the escaping bug in toJSON() and introduces new restrictive defaults in load(): secretsFromEnv now explicitly defaults to false, and a maxDepth parameter protects against DoS via deeply nested structures. JSDoc security warnings have been added to all import map options.

Who is affected?

Applications are vulnerable if they:

  1. Serialize untrusted data via `JSON.stringify()` on Serializable objects, then deserialize with `load()` — Trusting your own serialization output makes you vulnerable if user-controlled data (e.g., from LLM responses, metadata fields, or user inputs) contains 'lc' key structures.
  2. Deserialize untrusted data with `load()` — Directly deserializing untrusted data that may contain injected 'lc' structures.
  3. Use LangGraph checkpoints — Checkpoint serialization/deserialization paths may be affected.

The most common attack vector is through LLM response fields like additional_kwargs or response_metadata, which can be controlled via prompt injection and then serialized/deserialized in streaming operations.

Impact

Attackers who control serialized data can extract environment variable secrets by injecting {"lc": 1, "type": "secret", "id": ["ENV_VAR"]} to load environment variables during deserialization (when secretsFromEnv: true). They can also instantiate classes with controlled parameters by injecting constructor structures to instantiate any class within the provided import maps with attacker-controlled parameters, potentially triggering side effects such as network calls or file operations.

Key severity factors:

  • Affects the serialization path—applications trusting their own serialization output are vulnerable
  • Enables secret extraction when combined with secretsFromEnv: true
  • LLM responses in additional_kwargs can be controlled via prompt injection

Exploit example

import { load } from "@langchain/core/load";

// Attacker injects secret structure into user-controlled data
const attackerPayload = JSON.stringify({
  user_data: {
    lc: 1,
    type: "secret",
    id: ["OPENAI_API_KEY"],
  },
});

process.env.OPENAI_API_KEY = "sk-secret-key-12345";

// With secretsFromEnv: true, the secret is extracted
const deserialized = await load(attackerPayload, { secretsFromEnv: true });

console.log(deserialized.user_data); // "sk-secret-key-12345" - SECRET LEAKED!

Security hardening changes

This patch introduces the following changes to load():

  1. `secretsFromEnv` default changed to `false`: Disables automatic secret loading from environment variables. Secrets not found in secretsMap now throw an error instead of being loaded from process.env. This fail-safe behavior ensures missing secrets are caught immediately rather than silently continuing with null.
  2. New `maxDepth` parameter (defaults to 50): Protects against denial-of-service attacks via deeply nested JSON structures that could cause stack overflow.
  3. Escape mechanism in `toJSON()`: User-controlled objects containing 'lc' keys are now wrapped in {"__lc_escaped__": {...}} during serialization and unwrapped as plain data during deserialization.
  4. JSDoc security warnings: All import map options (importMap, optionalImportsMap, optionalImportEntrypoints) now include security warnings about never populating them from user input.

Migration guide

No changes needed for most users

If you're deserializing standard LangChain types (messages, documents, prompts) using the core import map, your code will work without changes:

import { load } from "@langchain/core/load";

// Works with default settings
const obj = await load(serializedData);

For secrets from environment

secretsFromEnv now defaults to false, and missing secrets throw an error. If you need to load secrets:

import { load } from "@langchain/core/load";

// Provide secrets explicitly (recommended)
const obj = await load(serializedData, {
  secretsMap: { OPENAI_API_KEY: process.env.OPENAI_API_KEY },
});

// Or explicitly opt-in to load from env (only use with trusted data)
const obj = await load(serializedData, { secretsFromEnv: true });

Warning: Only enable secretsFromEnv if you trust the serialized data. Untrusted data could extract any environment variable.

Note: If a secret reference is encountered but not found in secretsMap (and secretsFromEnv is false or the secret is not in the environment), an error is thrown. This fail-safe behavior ensures you're aware of missing secrets rather than silently receiving null values.

For deeply nested structures

If you have legitimate deeply nested data that exceeds the default depth limit of 50:

import { load } from "@langchain/core/load";

const obj = await load(serializedData, { maxDepth: 100 });

For custom import maps

If you provide custom import maps, ensure they only contain trusted modules:

import { load } from "@langchain/core/load";
import * as myModule from "./my-trusted-module";

// GOOD - explicitly include only trusted modules
const obj = await load(serializedData, {
  importMap: { my_module: myModule },
});

// BAD - never populate from user input
const obj = await load(serializedData, {
  importMap: userProvidedImports, // DANGEROUS!
});

Credited to eyurtsev, ccurme, mdrxy, 0xn3va, yardenporat353, VladimirEliTokarev, hntrl, siewer, jacoblee93.

Questions

Is this the same as CVE-2025-68664?

It is the same flaw class in a different codebase. CVE-2025-68664 is langchain-core for Python. This one is LangChain JS, with a different set of fixed versions.

Does it affect LangGraph checkpoints?

The advisory lists LangGraph checkpoint serialization and deserialization paths as possibly affected, so upgrade @langchain/core in those apps.

Why is class instantiation limited in JS?

Only classes in the supplied import maps can be built. The core map has standard types, and you must never add modules from user input.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More LangChain vulnerabilities

All LangChain entries