CVE-2026-40087: LangChain Incomplete f-string Validation in Prompt Templates
Summary
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 ↓
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.
No signup required · Results in about 60 seconds
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.840.3.84pip install --upgrade "langchain-core==0.3.84" -
>= 1.0.0a1, < 1.2.281.2.28pip 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 →
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.
References
Related vulnerabilities
Recent vulnerabilities recorded for langchain-core.