CVE-2026-40087: LangChain Incomplete f-string Validation in Prompt Templates

langchain-core Updated 18 Jul 2026

Summary

13/07/2026
Yes i
Medium
5.3

CVE-2026-40087: LangChain has incomplete f-string validation in prompt templates. Affects langchain-core across 2 version ranges.

< 0.3.84 >= 1.0.0a1, < 1.2.28

Fixed in 0.3.84 or 1.2.28, depending on the release line you run. How to fix ↓

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

LangChain is a popular framework designed for building applications that utilize language models. It provides various tools for creating prompt templates, which are essential for interacting with these models. However, an incomplete validation mechanism for f-string templates has exposed certain classes to potential security risks, particularly when handling untrusted input.

Vulnerability Detail

The vulnerability in LangChain arises from incomplete f-string validation in specific prompt template classes, namely DictPromptTemplate and ImagePromptTemplate. These classes allowed the use of f-string templates that could include attribute access and indexing expressions, which were evaluated during formatting. This could lead to unintended exposure of internal object states or sensitive data. Additionally, the validation mechanism failed to reject nested replacement fields within format specifiers, potentially allowing for further exploitation. The practical impact of this vulnerability is contingent upon the application's handling of template strings and the objects passed into formatting, with higher risks associated with applications that permit user-defined templates.

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.84 0.3.84
    pip install --upgrade "langchain-core==0.3.84"
  • >= 1.0.0a1, < 1.2.28 1.2.28
    pip install --upgrade "langchain-core==1.2.28"

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

As a temporary measure, avoid using untrusted template strings or restrict the input to known safe variables. Ensure that only hardcoded templates are utilized, or limit user input to simple variable values without complex expressions.

Conclusion

The vulnerability CVE-2026-40087 in LangChain highlights the importance of robust validation mechanisms for template handling. By updating to the latest versions and implementing best practices, developers can mitigate the risks associated with this issue.

See every vulnerability recorded for langchain-core →

Share this vulnerability

FAQ

CVE-2026-40087 is a vulnerability in LangChain that involves incomplete validation of f-string templates, potentially allowing for unauthorized access to internal data.

You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.

The risks include potential exposure of sensitive internal data and unintended behavior in applications that allow user-defined templates with complex expressions.

If immediate updates are not possible, implement workarounds by restricting template inputs to safe variables and avoiding untrusted template strings.

The CVSS score for this vulnerability is 5.3, indicating a moderate level of risk.

Related vulnerabilities

Recent vulnerabilities recorded for langchain-core.

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.84 0.3.84
    pip install --upgrade "langchain-core==0.3.84"
  • >= 1.0.0a1, < 1.2.28 1.2.28
    pip install --upgrade "langchain-core==1.2.28"

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback