CVE-2026-40087: langchain · Template Injection
Affects langchainSource CVE Database V5
Not known to be exploited · CVSS 5.3 Medium : upgrade to 1.2.28 or 0.3.83 when convenient.
Data as of 30 Oct 2026, 11:52 UTC
- EPSS
- 0.2% chance of exploitation in 30 days – higher than 17% of CVEsExploit Prediction Scoring System: the likelihood attackers will use this flaw soon.
- Patch
- Available – fixed in 1.2.28, 0.3.83, 0.3.84
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:NExploitation evidence
Disclosed: evidence found.
CVE published 9 Apr 2026
Detectable: no evidence on record.
No public nuclei template indexed
Weaponized: no evidence on record.
No public exploit code indexed in Metasploit or Exploit-DB
Exploited in the wildExploited: no evidence on record.
Not in CISA KEV and no source reports exploitation
Observed by OffSeq MirageSeen by Mirage: no evidence on record.
No attack traffic recorded by OffSeq Mirage sensors
A missing step is not evidence of safety. Sources: cve.org (opens in a new tab), the Metasploit, Exploit-DB and nuclei-templates index as of 30 Oct 2026.
What to do
Upgrade langchain to 1.2.28 or 0.3.83; langchain to 0.3.84.
Affected software
| Product | Affected | Fixed in |
|---|---|---|
| langchain-ailangchain | Affected
| Fixed in
|
| langchain-ailangchain | Affected
| Fixed in
|
PyPIlangchainpkg:pypi/langchainOther threats | Affected
| Fixed in
|
Check your own hosts for these packages with threat-finder (opens in a new tab), our free open-source scanner.
AI-suggested
This vulnerability is fixed in LangChain versions 0.3.84 and 1.2.28. Users should upgrade to at least these versions to remediate the issue. Patch status is not explicitly stated beyond the fixed versions; therefore, users should consult the official LangChain release notes or vendor advisory for the latest remediation guidance.
Description
LangChain is a framework for building agents and LLM-powered applications. Prior to 0.3.84 and 1.2.28, LangChain's f-string prompt-template validation was incomplete in two respects. First, some prompt template classes accepted f-string templates and formatted them without enforcing the same attribute-access validation as PromptTemplate. In particular, DictPromptTemplate and ImagePromptTemplate could accept templates containing attribute access or indexing expressions and subsequently evaluate those expressions during formatting. Second, f-string validation based on parsed top-level field names did not reject nested replacement fields inside format specifiers. In this pattern, the nested replacement field appears in the format specifier rather than in the top-level field name. As a result, earlier validation based on parsed field names did not reject the template even though Python formatting would still attempt to resolve the nested expression at runtime. This vulnerability is fixed in 0.3.84 and 1.2.28.
References
- github.com/langchain-ai/langchain/security/advisories/GHSA-926x-3r5x-gfhw (opens in a new tab)
- github.com/langchain-ai/langchain/pull/36612 (opens in a new tab)
- github.com/langchain-ai/langchain/pull/36613 (opens in a new tab)
- github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b (opens in a new tab)
- github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258 (opens in a new tab)
- github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D0.3.84 (opens in a new tab)
- github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D1.2.28 (opens in a new tab)