Join the Cyber Forum: Threat Intel on May 12, 2026 to learn how AI is reshaping threat defense.Join the Virtual Cyber Forum: Threat IntelRegister Now
Experiencing a Breach?Blog
Get StartedContact Us
SentinelOne
  • Platform
    Platform Overview
    • Singularity Platform
      Welcome to Integrated Enterprise Security
    • AI for Security
      Leading the Way in AI-Powered Security Solutions
    • Securing AI
      Accelerate AI Adoption with Secure AI Tools, Apps, and Agents.
    • How It Works
      The Singularity XDR Difference
    • Singularity Marketplace
      One-Click Integrations to Unlock the Power of XDR
    • Pricing & Packaging
      Comparisons and Guidance at a Glance
    Data & AI
    • Purple AI
      Accelerate SecOps with Generative AI
    • Singularity Hyperautomation
      Easily Automate Security Processes
    • AI-SIEM
      The AI SIEM for the Autonomous SOC
    • AI Data Pipelines
      Security Data Pipeline for AI SIEM and Data Optimization
    • Singularity Data Lake
      AI-Powered, Unified Data Lake
    • Singularity Data Lake for Log Analytics
      Seamlessly Ingest Data from On-Prem, Cloud or Hybrid Environments
    Endpoint Security
    • Singularity Endpoint
      Autonomous Prevention, Detection, and Response
    • Singularity XDR
      Native & Open Protection, Detection, and Response
    • Singularity RemoteOps Forensics
      Orchestrate Forensics at Scale
    • Singularity Threat Intelligence
      Comprehensive Adversary Intelligence
    • Singularity Vulnerability Management
      Application & OS Vulnerability Management
    • Singularity Identity
      Identity Threat Detection and Response
    Cloud Security
    • Singularity Cloud Security
      Block Attacks with an AI-Powered CNAPP
    • Singularity Cloud Native Security
      Secure Cloud and Development Resources
    • Singularity Cloud Workload Security
      Real-Time Cloud Workload Protection Platform
    • Singularity Cloud Data Security
      AI-Powered Threat Detection for Cloud Storage
    • Singularity Cloud Security Posture Management
      Detect and Remediate Cloud Misconfigurations
    Securing AI
    • Prompt Security
      Secure AI Tools Across Your Enterprise
  • Why SentinelOne?
    Why SentinelOne?
    • Why SentinelOne?
      Cybersecurity Built for What’s Next
    • Our Customers
      Trusted by the World’s Leading Enterprises
    • Industry Recognition
      Tested and Proven by the Experts
    • About Us
      The Industry Leader in Autonomous Cybersecurity
    Compare SentinelOne
    • Arctic Wolf
    • Broadcom
    • CrowdStrike
    • Cybereason
    • Microsoft
    • Palo Alto Networks
    • Sophos
    • Splunk
    • Trellix
    • Trend Micro
    • Wiz
    Verticals
    • Energy
    • Federal Government
    • Finance
    • Healthcare
    • Higher Education
    • K-12 Education
    • Manufacturing
    • Retail
    • State and Local Government
  • Services
    Managed Services
    • Managed Services Overview
      Wayfinder Threat Detection & Response
    • Threat Hunting
      World-Class Expertise and Threat Intelligence
    • Managed Detection & Response
      24/7/365 Expert MDR Across Your Entire Environment
    • Incident Readiness & Response
      DFIR, Breach Readiness, & Compromise Assessments
    Support, Deployment, & Health
    • Technical Account Management
      Customer Success with Personalized Service
    • SentinelOne GO
      Guided Onboarding & Deployment Advisory
    • SentinelOne University
      Live and On-Demand Training
    • Services Overview
      Comprehensive Solutions for Seamless Security Operations
    • SentinelOne Community
      Community Login
  • Partners
    Our Network
    • MSSP Partners
      Succeed Faster with SentinelOne
    • Singularity Marketplace
      Extend the Power of S1 Technology
    • Cyber Risk Partners
      Enlist Pro Response and Advisory Teams
    • Technology Alliances
      Integrated, Enterprise-Scale Solutions
    • SentinelOne for AWS
      Hosted in AWS Regions Around the World
    • Channel Partners
      Deliver the Right Solutions, Together
    • SentinelOne for Google Cloud
      Unified, Autonomous Security Giving Defenders the Advantage at Global Scale
    • Partner Locator
      Your Go-to Source for Our Top Partners in Your Region
    Partner Portal→
  • Resources
    Resource Center
    • Case Studies
    • Data Sheets
    • eBooks
    • Reports
    • Videos
    • Webinars
    • Whitepapers
    • Events
    View All Resources→
    Blog
    • Feature Spotlight
    • For CISO/CIO
    • From the Front Lines
    • Identity
    • Cloud
    • macOS
    • SentinelOne Blog
    Blog→
    Tech Resources
    • SentinelLABS
    • Ransomware Anthology
    • Cybersecurity 101
  • About
    About SentinelOne
    • About SentinelOne
      The Industry Leader in Cybersecurity
    • Investor Relations
      Financial Information & Events
    • SentinelLABS
      Threat Research for the Modern Threat Hunter
    • Careers
      The Latest Job Opportunities
    • Press & News
      Company Announcements
    • Cybersecurity Blog
      The Latest Cybersecurity Threats, News, & More
    • FAQ
      Get Answers to Our Most Frequently Asked Questions
    • DataSet
      The Live Data Platform
    • S Foundation
      Securing a Safer Future for All
    • S Ventures
      Investing in the Next Generation of Security, Data and AI
  • Pricing
Get StartedContact Us
CVE Vulnerability Database
Vulnerability Database/CVE-2026-40087

CVE-2026-40087: LangChain RCE Vulnerability

CVE-2026-40087 is a remote code execution flaw in LangChain framework caused by incomplete f-string prompt-template validation. This article covers the technical details, affected versions, security impact, and mitigation.

Published: April 9, 2026

CVE-2026-40087 Overview

CVE-2026-40087 is an input validation vulnerability in LangChain, a popular framework for building agents and LLM-powered applications. The vulnerability exists in LangChain's f-string prompt-template validation mechanism, which was incomplete in two critical respects. Certain prompt template classes, specifically DictPromptTemplate and ImagePromptTemplate, accepted f-string templates containing attribute access or indexing expressions and evaluated those expressions during formatting without proper validation. Additionally, f-string validation based on parsed top-level field names failed to reject nested replacement fields inside format specifiers, allowing malicious expressions to be resolved at runtime.

Critical Impact

Attackers can bypass prompt template validation to inject malicious expressions that are evaluated during template formatting, potentially leading to information disclosure in LLM-powered applications.

Affected Products

  • LangChain versions prior to 0.3.84
  • LangChain versions prior to 1.2.28
  • Applications using DictPromptTemplate or ImagePromptTemplate with f-string template format

Discovery Timeline

  • April 9, 2026 - CVE-2026-40087 published to NVD
  • April 9, 2026 - Last updated in NVD database

Technical Details for CVE-2026-40087

Vulnerability Analysis

This vulnerability is classified as CWE-1336 (Improper Neutralization of Special Elements Used in a Template Engine). The root issue lies in LangChain's inconsistent application of f-string template validation across different prompt template classes.

While PromptTemplate enforced attribute-access validation to prevent malicious template expressions, DictPromptTemplate and ImagePromptTemplate bypassed these security controls. These classes would accept templates containing potentially dangerous attribute access or indexing expressions (e.g., {obj.attribute} or {obj[key]}) and evaluate them during the formatting process.

The second aspect of this vulnerability involves nested replacement fields within format specifiers. Python's f-string syntax allows nested fields like {value:{width}}, where the format specifier itself contains a replacement field. LangChain's validation only inspected top-level field names, failing to detect and reject nested expressions that Python's formatting engine would still attempt to resolve at runtime.

Root Cause

The root cause is incomplete input validation in LangChain's prompt template handling. The security controls implemented in PromptTemplate were not consistently applied to DictPromptTemplate and ImagePromptTemplate. Additionally, the f-string parsing logic only examined top-level field names rather than recursively validating the entire template structure, including format specifiers.

Attack Vector

This vulnerability is exploitable over the network with low attack complexity and requires no authentication. An attacker who can influence prompt template content—such as through user-supplied input in an LLM application—could craft malicious templates that bypass validation. When these templates are formatted, the embedded expressions would be evaluated, potentially exposing sensitive object attributes or internal application state.

The attack vector involves:

  1. Identifying an application using vulnerable LangChain versions with DictPromptTemplate or ImagePromptTemplate
  2. Crafting a malicious f-string template containing attribute access expressions or nested replacement fields
  3. Submitting the template to bypass validation checks
  4. Triggering template formatting to evaluate the injected expressions
python
# Security patch in libs/core/langchain_core/prompts/dict.py
# Source: https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b

 """Dict prompt template."""
 
+from __future__ import annotations
+
 import warnings
 from functools import cached_property
 from typing import Any, Literal, Optional
 
+from pydantic import model_validator
 from typing_extensions import override
 
 from langchain_core.load import dumpd
python
# Security patch in libs/core/langchain_core/prompts/image.py
# Source: https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b

 from langchain_core.prompts.string import (
     DEFAULT_FORMATTER_MAPPING,
     PromptTemplateFormat,
+    get_template_variables,
 )
 from langchain_core.runnables import run_in_executor

Detection Methods for CVE-2026-40087

Indicators of Compromise

  • Unusual prompt template strings containing attribute access patterns like {variable.attribute} or indexing expressions {variable[key]}
  • Template formatting errors or unexpected attribute resolution in application logs
  • Evidence of nested replacement fields in format specifiers within prompt templates
  • Attempted access to internal object attributes through template expressions

Detection Strategies

  • Monitor application logs for template validation errors or unexpected formatting behavior in LangChain prompt processing
  • Implement static code analysis to identify usage of DictPromptTemplate or ImagePromptTemplate with user-controllable input
  • Review application code for instances where external input can influence prompt template content
  • Deploy runtime monitoring to detect attribute access patterns in template strings that may indicate exploitation attempts

Monitoring Recommendations

  • Enable verbose logging for LangChain prompt template processing to capture potential bypass attempts
  • Implement input validation at the application layer before passing data to LangChain template classes
  • Monitor for anomalous patterns in LLM request logs that could indicate template injection
  • Set up alerts for unexpected exceptions during prompt template formatting operations

How to Mitigate CVE-2026-40087

Immediate Actions Required

  • Upgrade LangChain to version 0.3.84 or later for the 0.3.x branch
  • Upgrade LangChain to version 1.2.28 or later for the 1.x branch
  • Audit applications using DictPromptTemplate or ImagePromptTemplate with f-string templates
  • Review and restrict user input that can influence prompt template content

Patch Information

LangChain has released security patches in versions 0.3.84 and 1.2.28 that address this vulnerability. The fixes add model_validator decorators and proper template variable sanitization using the get_template_variables function to enforce consistent validation across all prompt template classes.

For detailed patch information, see:

  • GitHub Pull Request #36612
  • GitHub Pull Request #36613
  • GitHub Security Advisory GHSA-926x-3r5x-gfhw

Workarounds

  • Avoid using DictPromptTemplate or ImagePromptTemplate with f-string template format until patched versions can be deployed
  • Implement strict input validation to reject template strings containing attribute access or indexing patterns before passing to LangChain
  • Use allowlist-based validation for template variable names to prevent injection of malicious expressions
  • Consider using alternative template formats that do not support attribute access syntax
bash
# Upgrade LangChain to patched versions
pip install --upgrade langchain-core>=0.3.84  # For 0.3.x branch
# OR
pip install --upgrade langchain-core>=1.2.28  # For 1.x branch

# Verify installed version
pip show langchain-core | grep Version

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

  • Vulnerability Details
  • TypeRCE

  • Vendor/TechLangchain

  • SeverityMEDIUM

  • CVSS Score5.3

  • Known ExploitedNo
  • CVSS Vector
  • CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
  • Impact Assessment
  • ConfidentialityLow
  • IntegrityNone
  • AvailabilityNone
  • CWE References
  • CWE-1336
  • Technical References
  • GitHub Commit Update

  • GitHub Commit Update

  • GitHub Pull Request #36612

  • GitHub Pull Request #36613

  • GitHub Release 0.3.84

  • GitHub Release 1.2.28

  • GitHub Security Advisory GHSA-926x-3r5x-gfhw
  • Related CVEs
  • CVE-2026-30617: LangChain-ChatChat 0.3.1 RCE Vulnerability

  • CVE-2025-46059: LangChain GmailToolkit RCE Vulnerability

  • CVE-2024-46946: Langchain-experimental RCE Vulnerability

  • CVE-2024-27444: Langchain-experimental RCE Vulnerability
Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the World’s Most Advanced Cybersecurity Platform

See how our intelligent, autonomous cybersecurity platform can protect your organization now and into the future.

Try SentinelOne
  • Get Started
  • Get a Demo
  • Product Tour
  • Why SentinelOne
  • Pricing & Packaging
  • FAQ
  • Contact
  • Contact Us
  • Customer Support
  • SentinelOne Status
  • Language
  • Platform
  • Singularity Platform
  • Singularity Endpoint
  • Singularity Cloud
  • Singularity AI-SIEM
  • Singularity Identity
  • Singularity Marketplace
  • Purple AI
  • Services
  • Wayfinder TDR
  • SentinelOne GO
  • Technical Account Management
  • Support Services
  • Verticals
  • Energy
  • Federal Government
  • Finance
  • Healthcare
  • Higher Education
  • K-12 Education
  • Manufacturing
  • Retail
  • State and Local Government
  • Cybersecurity for SMB
  • Resources
  • Blog
  • Labs
  • Case Studies
  • Videos
  • Product Tours
  • Events
  • Cybersecurity 101
  • eBooks
  • Webinars
  • Whitepapers
  • Press
  • News
  • Ransomware Anthology
  • Company
  • About Us
  • Our Customers
  • Careers
  • Partners
  • Legal & Compliance
  • Security & Compliance
  • Investor Relations
  • S Foundation
  • S Ventures

©2026 SentinelOne, All Rights Reserved.

Privacy Notice Terms of Use

English