Skip to content

Conversation

@renovate
Copy link
Contributor

@renovate renovate bot commented Oct 30, 2024

Note: This PR body was truncated due to platform limits.

This PR contains the following updates:

Package Change Age Confidence
langchain (source) ^0.0.184^0.3.0 age confidence

GitHub Vulnerability Alerts

CVE-2024-7774

A path traversal vulnerability exists in the getFullPath method of langchain-ai/langchainjs version 0.2.5. This vulnerability allows attackers to save files anywhere in the filesystem, overwrite existing text files, read .txt files, and delete files. The vulnerability is exploited through the setFileContent, getParsedFile, and mdelete methods, which do not properly sanitize user input.

CVE-2025-68665

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!
});

Release Notes

langchain-ai/langchainjs (langchain)

v0.3.37

v0.3.36

Compare Source

v0.3.35

Compare Source

v0.3.34

Compare Source

v0.3.33

Compare Source

v0.3.32

Compare Source

v0.3.31

Compare Source

v0.3.30

Compare Source

v0.3.29

Compare Source

v0.3.28

Compare Source

v0.3.27

Compare Source

What's Changed

New Contributors

Full Changelog: langchain-ai/langchainjs@0.3.26...0.3.27

v0.3.26

Compare Source

What's Changed

Full Changelog: langchain-ai/langchainjs@0.3.25...0.3.26

v0.3.25

Compare Source

What's Changed

New Contributors

Full Changelog: langchain-ai/langchainjs@0.3.24...0.3.25

v0.3.24

Compare Source

What's Changed

New Contributors

Full Changelog: langchain-ai/langchainjs@0.3.23...0.3.24

v0.3.23

Compare Source

What's Changed

New Contributors

Full Changelog: langchain-ai/langchainjs@0.3.22...0.3.23

v0.3.22

Compare Source

Full Changelog: langchain-ai/langchainjs@0.3.21...0.3.22

v0.3.21

Compare Source

What's Changed

New Contributors

Full Changelog: langchain-ai/langchainjs@0.3.20...0.3.21

v0.3.20

Compare Source

What's Changed


Configuration

📅 Schedule: Branch creation - "" in timezone Europe/Oslo, Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot added the security label Oct 30, 2024
@renovate renovate bot force-pushed the renovate/npm-langchain-vulnerability branch from 4aeb5c4 to c4b9100 Compare August 14, 2025 19:57
@renovate renovate bot force-pushed the renovate/npm-langchain-vulnerability branch from c4b9100 to 1b0b641 Compare September 26, 2025 07:46
@renovate renovate bot force-pushed the renovate/npm-langchain-vulnerability branch from 1b0b641 to 7eefa74 Compare October 25, 2025 19:44
@renovate renovate bot force-pushed the renovate/npm-langchain-vulnerability branch from 7eefa74 to e11192d Compare November 19, 2025 04:02
@renovate renovate bot force-pushed the renovate/npm-langchain-vulnerability branch from e11192d to 8844b0b Compare December 24, 2025 19:03
@renovate renovate bot changed the title Update dependency langchain to ^0.2.0 [SECURITY] Update dependency langchain to ^0.3.0 [SECURITY] Dec 24, 2025
@renovate
Copy link
Contributor Author

renovate bot commented Dec 24, 2025

⚠️ Artifact update problem

Renovate failed to update an artifact related to this branch. You probably do not want to merge this PR as-is.

♻ Renovate will retry this branch, including artifacts, only when one of the following happens:

  • any of the package files in this branch needs updating, or
  • the branch becomes conflicted, or
  • you click the rebase/retry checkbox if found above, or
  • you rename this PR's title to start with "rebase!" to trigger it manually

The artifact failure details are included below:

File name: package-lock.json
npm warn Unknown env config "store". This will stop working in the next major version of npm.
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: llmlabs@0.0.1
npm error Found: @langchain/core@1.1.8
npm error node_modules/@langchain/core
npm error   peer @langchain/core@"1.1.8" from @langchain/anthropic@1.3.3
npm error   node_modules/@langchain/anthropic
npm error     peerOptional @langchain/anthropic@"*" from langchain@0.3.37
npm error     node_modules/langchain
npm error       langchain@"^0.3.0" from the root project
npm error   peer @langchain/core@"^1.0.0" from @langchain/aws@1.1.0
npm error   node_modules/@langchain/aws
npm error     peerOptional @langchain/aws@"*" from langchain@0.3.37
npm error     node_modules/langchain
npm error       langchain@"^0.3.0" from the root project
npm error   2 more (@langchain/cerebras, @langchain/cohere)
npm error
npm error Could not resolve dependency:
npm error peer @langchain/core@">=0.3.58 <0.4.0" from langchain@0.3.37
npm error node_modules/langchain
npm error   langchain@"^0.3.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /runner/cache/others/npm/_logs/2026-01-01T03_42_35_473Z-eresolve-report.txt
npm error A complete log of this run can be found in: /runner/cache/others/npm/_logs/2026-01-01T03_42_35_473Z-debug-0.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant