LangChain has incomplete f-string validation in prompt templates
CVE-2026-40087 · GHSA-926x-3r5x-gfhw · published 2026-04-08 · updated 2026-04-10
- Severity
- Medium
- CVSS score
- 5.3
- Chance of exploitation (EPSS)
- 0.27%
- Fixed in
- 1.2.28
- Exploitation No known exploitation
- Automatable Yes
- Technical impact Partial
- CISA SSVC
The direct issue in DictPromptTemplate and ImagePromptTemplate allowed attribute access and indexing expressions to survive template construction and then be evaluated during formatting. When richer Python objects were passed into formatting, this could expose internal fields or nested data to prompt output, model context, or logs. The nested format-spec issue is narrower in scope. It bypassed the intended validation rules for f-string templates, but in simple cases it results in an invalid format specifier error rather than direct disclosure. Accordingly, its practical impact is lower than that of direct top-level attribute traversal. Overall, the practical severity depends on deployment.
Upgrade langchain-core to 1.2.28 or later. If you start it from an MCP config with npx or uvx, pin that version so an old cached copy is not used.
The fix consists of two changes. First, LangChain now applies f-string safety validation consistently to DictPromptTemplate and ImagePromptTemplate, so templates containing attribute access or indexing expressions are rejected during construction and deserialization. Second, LangChain now rejects nested replacement fields inside f-string format specifiers. Concretely, LangChain validates parsed f-string fields and raises an error for: variable names containing attribute access or indexing syntax such as .
| Package | Registry | Affected | Fixed in |
|---|---|---|---|
| langchain-core | PyPI | < 0.3.83 | 0.3.84 |
| langchain-core | PyPI | >= 1.0.0a1, < 1.2.28 | 1.2.28 |
- CriticalUnauthenticated Remote Code Execution in Langflow via Public Flow Build EndpointlangflowExploited
- CriticalRay is vulnerable to Critical RCE via Safari & Firefox Browsers through DNS Rebinding AttackrayExploited
- CriticalLangflow Unauth RCElangflow, langflow-baseExploited
- HighLiteLLM: Authenticated command execution via MCP stdio test endpointslitellmExploited
- CriticalMLflow vulnerable to remote code execution on unauthenticated servers via third-party scorer deserialization importing caller-placed artifacmlflow
- CriticalAgno: Arbitrary code execution via `eval()` on `field_type` in `FunctionCall`agno
- CriticalLangChain serialization injection vulnerability enables secret extraction in dumps/loads APIslangchain-core, langchain-core
- HighLangChain vulnerable to unsafe deserialization of attacker-controlled objects through overly broad `load()` allowlistslangchain-core, langchain-core
- HighLangChain Core has Path Traversal vulnerabilites in legacy `load_prompt` functionslangchain-core
- HighLangChain Vulnerable to Template Injection via Attribute Access in Prompt Templateslangchain-core, langchain-core
- Mediumlangchain-core allows unauthorized users to read arbitrary files from the host file systemlangchain-core, langchain-core, langchain-core
- MediumLangChain's XMLOutputParser vulnerable to XML Entity Expansionlangchain-core
The impact, patch and workaround text comes from the advisory, shortened (GitHub Advisory Database, CC BY 4.0). Proof-of-concept and reproduction sections and code are left out; the original advisory has them.