{"id":"CVE-2026-40087","published":"2026-04-09T19:34:55Z","modified":"2026-04-14T14:48:03Z","title":"LangChain has incomplete f-string validation in prompt templates","vendor":"langchain-ai","product":"langchain","tier":"tail","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.","provenance":"source","from":"CVE.org"},"cvss":{"score":5.3,"severity":"MEDIUM","version":"3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00272,"percentile":0.19982,"provenance":"source"},"cwes":[{"id":"CWE-1336","name":"Improper Neutralization of Special Elements Used in a Template Engine"}],"references":[{"url":"https://github.com/langchain-ai/langchain/security/advisories/GHSA-926x-3r5x-gfhw","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/langchain-ai/langchain/pull/36612","tags":["x_refsource_MISC"]},{"url":"https://github.com/langchain-ai/langchain/pull/36613","tags":["x_refsource_MISC"]},{"url":"https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b","tags":["x_refsource_MISC"]},{"url":"https://github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258","tags":["x_refsource_MISC"]},{"url":"https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D0.3.84","tags":["x_refsource_MISC"]},{"url":"https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D1.2.28","tags":["x_refsource_MISC"]}],"priority":{"score":7.7,"factors":[{"name":"EPSS percentile","points":4.0},{"name":"CVSS severity","points":3.71}]},"vendorSlug":"langchain-ai","affectedVersions":[{"vendor":"langchain-ai","product":"langchain","versions":["< 0.3.83",">= 1.0.0a1, < 1.2.28"]}],"ssvc":{"exploitation":"none","automatable":"yes","technicalImpact":"partial","timestamp":"2026-04-14T14:47:52.978194Z","from":"CISA ADP","provenance":"source"},"affected":[{"ecosystem":"PyPI","package":"langchain-core","vulnerableRanges":["<0.3.84",">=1.0.0a1, <1.2.28"],"patched":["0.3.84","1.2.28"],"from":["GHSA-926x-3r5x-gfhw","PYSEC-2026-2563"],"provenance":"source"}],"summary":{"text":"LangChain's f-string prompt-template validation in the langchain package is incomplete: the DictPromptTemplate and ImagePromptTemplate classes accept f-string templates containing attribute-access or indexing expressions and evaluate them during formatting, and the validation also fails to reject nested replacement fields placed inside format specifiers. An attacker who can supply a template to these classes over the network without authentication or user interaction can cause the embedded expressions to be evaluated, with a low-impact confidentiality effect.","provenance":"ai","model":"claude-haiku-5-5","generatedAt":"2026-11-20T22:14:56Z"},"euvd":{"id":"EUVD-2026-21063","exploited":false,"provenance":"source"},"lineage":{"familyId":"fam-langchain-ai-langchain-cve-2024-10940","parents":[{"from":"CVE-2024-10940","to":"CVE-2026-40087","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["libs/core/langchain_core/prompts/image.py"],"commits":["https://github.com/langchain-ai/langchain/commit/c1e742347f9701aadba8920e4d1f79a636e50b68","https://github.com/langchain-ai/langchain/commit/7d481f10102f43559cc57bcad7eba291067939ee","https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b","https://github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258"],"basis":"rarely changed file"}]},{"from":"CVE-2025-65106","to":"CVE-2026-40087","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["libs/core/langchain_core/prompts/string.py"],"commits":["https://github.com/langchain-ai/langchain/commit/c4b6ba254e1a49ed91f2e268e6484011c540542a","https://github.com/langchain-ai/langchain/commit/fa7789d6c21222b85211755d822ef698d3b34e00","https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b","https://github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258"],"basis":"shared function","functions":["get_template_variables"]}]}],"packageHistory":[{"cve":"CVE-2025-68664","published":"2025-12-23","fixed":"1.2.5","kev":false,"link":{"from":"CVE-2025-68664","to":"CVE-2026-40087","relation":"successor","confidence":"low","kind":"sequence","evidence":[{"kind":"version-step","provenance":"source","package":"PyPI:langchain-core","fromFixed":"0.3.81","toFixed":"0.3.84","daysApart":107}]}},{"cve":"CVE-2026-26013","published":"2026-02-10","fixed":"1.2.11","kev":false},{"cve":"CVE-2026-34070","published":"2026-03-31","fixed":"1.2.22","kev":false,"link":{"from":"CVE-2026-34070","to":"CVE-2026-40087","relation":"successor","confidence":"low","kind":"sequence","evidence":[{"kind":"version-step","provenance":"source","package":"PyPI:langchain-core","fromFixed":"1.2.22","toFixed":"1.2.28","daysApart":9}]}},{"cve":"CVE-2026-40087","published":"2026-04-09","fixed":"1.2.28","kev":false},{"cve":"CVE-2026-44843","published":"2026-05-26","fixed":"1.3.3","kev":false,"link":{"from":"CVE-2026-40087","to":"CVE-2026-44843","relation":"successor","confidence":"low","kind":"sequence","evidence":[{"kind":"version-step","provenance":"source","package":"PyPI:langchain-core","fromFixed":"1.2.28","toFixed":"1.3.3","daysApart":47},{"kind":"version-step","provenance":"source","package":"PyPI:langchain-core","fromFixed":"0.3.84","toFixed":"0.3.85","daysApart":47}]}}],"package":"PyPI:langchain-core"}}