# CVE-2026-40087: LangChain has incomplete f-string validation in prompt templates

- Priority: **Routine**
- Reason: Not severe (CVSS 5.3, network access); no exploitation reported by the 5 checked sources
- Next step: Fix in the normal cadence
- Status: published
- Published: 2026-04-09 · Modified: 2026-04-14
- Aliases: GHSA-926x-3r5x-gfhw, PYSEC-2026-2563, CGA-h9qq-qw3w-4vcv, CGA-rf7q-x769-vjpj, CGA-49gv-2v6j-pjwm, CGA-7j3w-98c2-9289, CGA-7jqp-fr37-mh35, CGA-92ch-7cch-j63f, CGA-c3j7-2jj3-4wm3, CGA-g7q7-9qmq-x695, CGA-hf5w-vmg9-cqg9, CGA-jp42-ww69-q97m, CGA-v984-g369-25r2, CGA-wc34-pp9j-h84v
- Record: https://cvemate.com/vulnerability/CVE-2026-40087 · JSON: https://cvemate.com/vulnerability/CVE-2026-40087/json

## Description

```text
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.
```

## Signals

- CVSS: 5.3 medium (v3.1, CVE.org) CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
- EPSS: 0.278%, percentile 21.615%, as of 2026-12-04
- Known exploited (KEV): CISA not listed, ENISA not listed, CIRCL not listed
- Ransomware use: none recorded
- Public exploits: 0

## Affected

- chainguard open-webui (Chainguard): \< 0.8.12-r3
- chainguard py3-langchain (Chainguard): \< 1.3.0-r0
- chainguard py3.10-langchain (Chainguard): \< 1.3.0-r0
- chainguard py3.11-langchain (Chainguard): \< 1.3.0-r0
- chainguard py3.12-langchain (Chainguard): \< 1.3.0-r0
- chainguard py3.13-langchain (Chainguard): \< 1.3.0-r0
- wolfi open-webui (Wolfi): \< 0.8.12-r3
- langchain-ai langchain: \< 0.3.83 \| ≥ 1.0.0a1, \< 1.2.28
- langchain langchain\_core: \< 0.3.84 \| ≥ 1.0.0, \< 1.2.28
- PyPI langchain-core (PyPI): \< 0.3.84 \| ≥ 1.0.0a1, \< 1.2.28

## References

- <https://github.com/langchain-ai/langchain/security/advisories/GHSA-926x-3r5x-gfhw>
- <https://github.com/langchain-ai/langchain/pull/36612>
- <https://github.com/langchain-ai/langchain/pull/36613>
- <https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b>
- <https://github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258>
- <https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D0.3.84>
- <https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D1.2.28>
- <https://nvd.nist.gov/vuln/detail/CVE-2026-40087>
- <https://github.com/langchain-ai/langchain>
- <https://pypi.org/project/langchain-core>
- <https://github.com/advisories/GHSA-926x-3r5x-gfhw>
- <https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/40xxx/CVE-2026-40087.json>

---

Data as of 2026-12-05T13:06:11.627Z. The priority label is CveMate's own model from public evidence, not an official rating, and it knows nothing about your assets. How labels are decided: https://cvemate.com/faq#priority
