CVE-2026-40087

LangChain has incomplete f-string validation in prompt templates

Published Apr 9, 2026 CVSS 3.1 · 5.3 Medium EPSS < 1% KEV · Not listed
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.

Analysis

AI-generated

Technical impact

LangChain, a Python framework for building agents and LLM‑powered applications, contains an incomplete validation of f‑string prompt templates in versions prior to 0.3.84 and 1.2.28. The bug allows DictPromptTemplate and ImagePromptTemplate to accept f‑string templates that contain attribute access or indexing expressions, and also fails to reject nested replacement fields inside format specifiers. Because Python’s formatter evaluates these expressions at runtime, an attacker can embed arbitrary Python code in a prompt template and cause the application to execute it, corresponding to CWE‑1336.

Affected Systems

The vulnerability applies to all installations of langchain‑ai/langchain released before core 0.3.84 and before 1.2.28. Any deployment that utilizes DictPromptTemplate or ImagePromptTemplate for dynamic prompt generation without upgrading to the patched versions remains vulnerable.

Risk and Exploitability

The CVSS base score of 5.3 indicates medium severity, and EPSS data is unavailable; the vulnerability is not listed in the CISA KEV catalog, suggesting limited known exploitation. The likely attack vector is local or insider, where an attacker can influence the prompt template that the application formats. Once a malicious template is processed, the injected expressions run with the process’s privileges, posing a credible risk to applications that accept user‑generated prompts. This exploit path requires the attacker to provide a crafted prompt template to the application, which is typically available only through trusted or privileged input channels.

Remediation

No solution or workaround provided in the CVE record.

OpenCVE Recommended Actions

  • Upgrade langchain to version 0.3.84 or 1.2.28 or newer, where the f‑string validation bug is fixed.
  • Validate any user‑supplied prompt templates using a whitelist or sandbox before rendering to prevent code execution.
  • Restrict access to template creation endpoints so that only trusted users can supply template strings.
  • Monitor application logs for unexpected template formatting errors or crashes that could indicate exploitation.
  • Apply least‑privilege principles to the process that renders prompts to limit impact if an exploit occurs.

Generated by OpenCVE AI on April 9, 2026 at 22:29 UTC.

Tracking

Sign in to view the affected projects.

Advisories

Source ID Title
Github GHSA Github GHSA GHSA-926x-3r5x-gfhw LangChain has incomplete f-string validation in prompt templates
History
Type Values Removed Values Added
First Time appeared Langchain
Langchain langchain Core
CPEs cpe:2.3:a:langchain:langchain_core:*:*:*:*:*:python:*:*
Vendors & Products Langchain
Langchain langchain Core
Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'yes', 'Exploitation': 'none', 'Technical Impact': 'partial'}, 'version': '2.0.3'}

Type Values Removed Values Added
First Time appeared Langchain-ai
Langchain-ai langchain
Vendors & Products Langchain-ai
Langchain-ai langchain
Type Values Removed Values Added
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.
Title LangChain has incomplete f-string validation in prompt templates
Weaknesses CWE-1336
References
Metrics cvssV3_1

{'score': 5.3, 'vector': 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N'}

Weaknesses
  • CWE-1336

    Improper Neutralization of Special Elements Used in a Template Engine

Sources

Status
PUBLISHED
Assigner
GitHub_M
Published
Updated
Apr 14, 2026, 2:48 PM
Reserved
Apr 9, 2026, 12:39 AM
Status
Analyzed
Published
Apr 9, 2026, 8:16 PM
Modified
Oct 25, 2026, 11:10 PM
Severity
Moderate
Public date
Apr 9, 2026, 7:34 PM