{"answers":{"affected":"5 open source packages ship an affected version, including langchain-core. It affects 1 product.","exploited":"There is no known exploitation of CVE-2026-40087 in the wild and no public exploit code.","fix":"Upgrade langchain-core to a fixed version for your release line: 0.3.84 or 1.2.28.","what":"CVE-2026-40087 is a medium-severity code injection vulnerability in langchain-ai langchain, published on 9 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim."},"fix_prompt":"Check this codebase for CVE-2026-40087 and fix it if it is affected.\n\nWhat it is: CVE-2026-40087 is a medium-severity code injection vulnerability in langchain-ai langchain, published on 9 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.\nExploitation: There is no known exploitation of CVE-2026-40087 in the wild and no public exploit code.\n\nAffected packages and fixed versions:\n- langchain-core (PyPI): affected all versions; fixed in 0.3.84, 1.2.28\n- langchain-core (PyPI): affected all versions; fixed in 0.3.84\n- langchain-core (PyPI): affected all versions; fixed in 0.3.84\n- langchain-core (PyPI): affected from 1.0.0a1; fixed in 1.2.28\n- langchain-core (PyPI): affected from 1.0.0a1; fixed in 1.2.28\n\nTask:\n1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.\n2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.\n3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.\n4. Run the tests and summarise what changed and why.\n5. If nothing in the project is affected, say so and change nothing.\n\nReference: https://insights.sbomify.com/CVE-2026-40087/ (Markdown: https://insights.sbomify.com/CVE-2026-40087/index.md)","id":"CVE-2026-40087","markdown":"https://insights.sbomify.com/CVE-2026-40087/index.md","name":"CVE-2026-40087","record":{"aliases":["ECHO-8479-4c4c-18a0","GHSA-926x-3r5x-gfhw","PYSEC-2026-2563","ROOT-APP-PYPI-CVE-2026-40087"],"analysis":{"component_type":"library","fix_type":"upgrade","impacts":["code_execution"],"network_reachable":"yes","non_default_config":false,"product_category":"LangChain Python library","requires_auth":"none","summary":"Incomplete f-string validation in LangChain prompt templates allows attackers to execute arbitrary code via crafted templates.","user_interaction":"not_required","vuln_class":"code_injection"},"analysis_generated_by":"qwen3.8-flash-next","assigner":"GitHub_M","cpe":[{"product":"langchain_core","vendor":"langchain"}],"cvss":{"score":5.3,"severity":"medium","source":"cna","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N","version":"3.1"},"cwes":[{"id":"CWE-1336","name":"Improper Neutralization of Special Elements Used in a Template Engine"}],"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.","ecosystems":["PyPI"],"exploits":{"exploitdb":0,"first_seen":null,"github_poc":0,"max_poc_stars":null,"metasploit":0,"nuclei":0,"refs":[],"tier":"none_known"},"has_fix":true,"headline":"LangChain has incomplete f-string validation in prompt templates","id":"CVE-2026-40087","indexable":true,"kev":null,"kind":"cve","links":{"ecosystem":"PyPI","product":null,"products":[],"type":"code_injection","year":"2026"},"n_packages":5,"n_references":7,"next":{"headline":"Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') in praisonai","id":"CVE-2026-40088"},"packages":[{"ecosystem":"PyPI","fixed":["0.3.84","1.2.28"],"introduced":["0","1.0.0a1"],"last_affected":[],"package":"langchain-core","purl":"pkg:pypi/langchain-core","source":"PYSEC-2026-2563"},{"ecosystem":"PyPI","fixed":["0.3.84"],"introduced":["0"],"last_affected":[],"package":"langchain-core","purl":null,"source":"GHSA-926x-3r5x-gfhw"},{"ecosystem":"PyPI","fixed":["0.3.84"],"introduced":["0"],"last_affected":[],"package":"langchain-core","purl":"pkg:pypi/langchain-core","source":"GHSA-926x-3r5x-gfhw"},{"ecosystem":"PyPI","fixed":["1.2.28"],"introduced":["1.0.0a1"],"last_affected":[],"package":"langchain-core","purl":null,"source":"GHSA-926x-3r5x-gfhw"},{"ecosystem":"PyPI","fixed":["1.2.28"],"introduced":["1.0.0a1"],"last_affected":[],"package":"langchain-core","purl":"pkg:pypi/langchain-core","source":"GHSA-926x-3r5x-gfhw"}],"prev":{"headline":"Rembg has a Path Traversal via Custom Model Loading","id":"CVE-2026-40086"},"products":["langchain"],"published":"2026-04-09","related":[{"cvss_score":9.3,"headline":"LangChain serialization injection vulnerability enables secret extraction in dumps/loads APIs","id":"CVE-2025-68664","kev_date_added":null,"published":"2025-12-23"},{"cvss_score":7.5,"headline":"LangChain Core has Path Traversal vulnerabilites in legacy `load_prompt` functions","id":"CVE-2026-34070","kev_date_added":null,"published":"2026-03-31"},{"cvss_score":3.7,"headline":"LangChain affected by SSRF via image_url token counting in ChatOpenAI.get_num_tokens_from_messages","id":"CVE-2026-26013","kev_date_added":null,"published":"2026-02-10"}],"sources":[{"class":"attribution","licence":"CVE Terms of Use (MITRE)","name":"CVE List","prefix":"CVE"},{"class":"attribution","licence":"CC BY 4.0","name":"GitHub Advisory Database","prefix":"GHSA"},{"class":"attribution","licence":"CC BY 4.0","name":"PyPA Advisory Database","prefix":"PYSEC"},{"class":"attribution","licence":"US public information, NVD API terms","name":"NVD"},{"class":"attribution","licence":"CWE Terms of Use","name":"CWE (MITRE)"},{"class":"attribution","licence":"FIRST CVSS licence","name":"CVSS (FIRST)"}],"ssvc":{"automatable":"yes","exploitation":"none","technical_impact":"partial"},"state":"PUBLISHED","updated":"2026-04-14","vendors":["langchain-ai"]},"summary":"Incomplete f-string validation in LangChain prompt templates allows attackers to execute arbitrary code via crafted templates.","url":"https://insights.sbomify.com/CVE-2026-40087/"}