CVE-2026-40087: LangChain incomplete f-string validation in prompt templates

CVE-2026-40087 · Severity: medium · CVSS 5.3 · Published 2026-04-09

LangChain, a framework for building AI applications, had a flaw in how it validated prompt templates. If an application allows users to provide their own template strings, an attacker could craft a template that accesses internal data or sensitive object properties. This could lead to the exposure of private information in the AI's output or application logs.

Technologies: Langchain Core, langchain-core (PyPI). Vendors: LangChain, PyPI.

Quick answers

Is CVE-2026-40087 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-40087 being exploited in the wild.
How severe is CVE-2026-40087?
Medium severity, with a CVSS score of 5.3, published 9 April 2026.
Which products and versions are affected?
langchain-core (PyPI) ECOSYSTEM:introduced=0,fixed=0.3.84, ECOSYSTEM:introduced=0,fixed=0.3.84,introduced=1.0.0a1,fixed=1.2.28.
Is there a fix for CVE-2026-40087?
Yes. langchain-core (PyPI): upgrade to 0.3.84, 1.2.28 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-40087 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2026-40087?
Check whether you run Langchain Core or langchain-core (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • langchain-core (PyPI): upgrade to 0.3.84, 1.2.28 or later
    pip install "langchain-core>=1.2.28"

Technical details

LangChain's f-string validation failed to properly sanitize input in DictPromptTemplate and ImagePromptTemplate, and failed to reject nested replacement fields within format specifiers. This vulnerability allows for improper neutralization of special elements (CWE-1336) and improper input validation (CWE-20). An attacker who can provide untrusted template strings can use Python attribute access (e.g., .__class__) or indexing to traverse internal objects passed into the template during formatting. This can result in the disclosure of internal fields or sensitive data to the model context or logs. The issue is resolved in langchain-core versions 0.3.84 and 1.2.28 by enforcing consistent f-string safety validation and rejecting nested replacement fields.

Affected products

  • LangChain langchain-core < 0.3.83, >= 1.0.0a1, < 1.2.28

Identifiers

  • CVE-2026-40087
  • GHSA-926x-3r5x-gfhw
  • PYSEC-2026-2563

Timeline

  • 2026-04-08: advisory: GitHub Advisory GHSA-926x-3r5x-gfhw published
  • 2026-04-08: patched: Fixes merged in PR #36612 and #36613
  • 2026-04-09: other: NVD published CVE-2026-40087

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.