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

- Severity: Medium 5.3 (CVSS:3.1, scored by GitHub_M) `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Likelihood of exploitation in the next 30 days (EPSS): 0.28%, higher than 21% of CVEs (2026-12-01)
- Published: 2026-04-08T21:51:32.000Z
- Modified: 2026-10-25T23:10:00.167Z
- Also known as: GHSA-926x-3r5x-gfhw, PYSEC-2026-2563
- Weaknesses: CWE-20, CWE-1336
- SSVC (CISA-ADP): exploitation none, automatable yes, technical impact partial
- Assigned by: GitHub_M

## 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.

(As written by CVE List.)

## Affected

- langchain-ai langchain: < 0.3.83; >= 1.0.0a1, < 1.2.28
- langchain-core (PyPI): before 0.3.84; from 1.0.0a1 before 1.2.28
- langchain langchain_core: before 0.3.84; from 1.0.0 before 1.2.28

## Every score

- GitHub_M: CVSS:3.1 5.3 Medium `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N`
- GitHub: CVSS:3.1 5.3 Medium `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N`
- PyPA Advisory Database: CVSS:3.1 5.3 Medium `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N`

## References

- <https://github.com/langchain-ai/langchain/security/advisories/GHSA-926x-3r5x-gfhw> (mitigation, vendor-advisory, web)
- <https://github.com/langchain-ai/langchain/pull/36612> (issue-tracking, patch, web)
- <https://github.com/langchain-ai/langchain/pull/36613> (issue-tracking, patch, web)
- <https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b> (patch, web)
- <https://github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258> (patch, web)
- <https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D0.3.84> (product, release-notes, web)
- <https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D1.2.28> (product, release-notes, web)
- <https://nvd.nist.gov/vuln/detail/CVE-2026-40087> (advisory)
- <https://github.com/langchain-ai/langchain> (package)
- <https://pypi.org/project/langchain-core> (package)
- <https://github.com/advisories/GHSA-926x-3r5x-gfhw> (advisory)

## Sources

- CVE List: [CVE-2026-40087](https://www.cve.org/CVERecord?id=CVE-2026-40087), CVE Terms of Use, modified 2026-04-14
- GitHub Advisory Database: [GHSA-926x-3r5x-gfhw](https://github.com/advisories/GHSA-926x-3r5x-gfhw), CC-BY-4.0, modified 2026-09-10
- NVD: [CVE-2026-40087](https://nvd.nist.gov/vuln/detail/CVE-2026-40087), Public domain, modified 2026-10-25
- PyPA Advisory Database: [PYSEC-2026-2563](https://osv.dev/vulnerability/PYSEC-2026-2563), CC-BY-4.0, modified 2026-07-13

---

Page: https://cve.day/CVE-2026-40087 · Whole record: https://cve.day/CVE-2026-40087.json · Rebuilt by cve.day 2026-11-25T22:59:18.418Z
