← Back to CVE Explorer

CVE-2026-40087

Full vulnerability record from the local CVENow database.

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.

Severity
MEDIUM
CVSS score
5.3 (v3.1)
Vulnerability status
Analyzed
Source identifier
Published
2026-04-09 20:16:27.400000
Last modified
2026-10-25 23:10:00.167000
View original CVE JSON
{
  "id": "CVE-2026-40087",
  "sourceIdentifier": "[email protected]",
  "published": "2026-04-09T20:16:27.400",
  "lastModified": "2026-10-25T23:10:00.167",
  "vulnStatus": "Analyzed",
  "cveTags": [],
  "descriptions": [
    {
      "lang": "en",
      "value": "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."
    },
    {
      "lang": "es",
      "value": "LangChain es un framework para construir agentes y aplicaciones impulsadas por LLM. Antes de 0.3.84 y 1.2.28, la validación de plantillas de prompt f-string de LangChain era incompleta en dos aspectos. Primero, algunas clases de plantillas de prompt aceptaban plantillas f-string y las formateaban sin aplicar la misma validación de acceso a atributos que PromptTemplate. En particular, DictPromptTemplate e ImagePromptTemplate podían aceptar plantillas que contenían acceso a atributos o expresiones de indexación y posteriormente evaluar esas expresiones durante el formateo. Segundo, la validación de f-string basada en nombres de campo de nivel superior analizados no rechazaba los campos de reemplazo anidados dentro de los especificadores de formato. En este patrón, el campo de reemplazo anidado aparece en el especificador de formato en lugar de en el nombre del campo de nivel superior. Como resultado, la validación anterior basada en nombres de campo analizados no rechazaba la plantilla a pesar de que el formateo de Python aún intentaría resolver la expresión anidada en tiempo de ejecución. Esta vulnerabilidad se corrige en 0.3.84 y 1.2.28."
    }
  ],
  "affected": [
    {
      "source": "[email protected]",
      "affectedData": [
        {
          "vendor": "langchain-ai",
          "product": "langchain",
          "versions": [
            {
              "version": "< 0.3.83",
              "status": "affected"
            },
            {
              "version": ">= 1.0.0a1, < 1.2.28",
              "status": "affected"
            }
          ]
        }
      ]
    }
  ],
  "metrics": {
    "cvssMetricV31": [
      {
        "source": "[email protected]",
        "type": "Secondary",
        "cvssData": {
          "version": "3.1",
          "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N",
          "baseScore": 5.3,
          "baseSeverity": "MEDIUM",
          "attackVector": "NETWORK",
          "attackComplexity": "LOW",
          "privilegesRequired": "NONE",
          "userInteraction": "NONE",
          "scope": "UNCHANGED",
          "confidentialityImpact": "LOW",
          "integrityImpact": "NONE",
          "availabilityImpact": "NONE"
        },
        "exploitabilityScore": 3.9,
        "impactScore": 1.4
      }
    ],
    "ssvcV203": [
      {
        "source": "134c704f-9b21-4f2e-91b3-4a467353bcc0",
        "ssvcData": {
          "timestamp": "2026-04-14T14:47:52.978194Z",
          "id": "CVE-2026-40087",
          "options": [
            {
              "exploitation": "none"
            },
            {
              "automatable": "yes"
            },
            {
              "technicalImpact": "partial"
            }
          ],
          "role": "CISA Coordinator",
          "version": "2.0.3"
        }
      }
    ]
  },
  "weaknesses": [
    {
      "source": "[email protected]",
      "type": "Secondary",
      "description": [
        {
          "lang": "en",
          "value": "CWE-1336"
        }
      ]
    }
  ],
  "configurations": [
    {
      "nodes": [
        {
          "operator": "OR",
          "negate": false,
          "cpeMatch": [
            {
              "vulnerable": true,
              "criteria": "cpe:2.3:a:langchain:langchain_core:*:*:*:*:*:python:*:*",
              "versionEndExcluding": "0.3.84",
              "matchCriteriaId": "0274A49C-E34C-4B49-B47F-025C54462E88"
            },
            {
              "vulnerable": true,
              "criteria": "cpe:2.3:a:langchain:langchain_core:*:*:*:*:*:python:*:*",
              "versionStartIncluding": "1.0.0",
              "versionEndExcluding": "1.2.28",
              "matchCriteriaId": "199ECAF5-9D89-4DDC-B084-F3A9CC0A36AA"
            }
          ]
        }
      ]
    }
  ],
  "references": [
    {
      "url": "https://github.com/langchain-ai/langchain/commit/6bab0ba3c12328008ddca3e0d54ff5a6151cd27b",
      "source": "[email protected]",
      "tags": [
        "Patch"
      ]
    },
    {
      "url": "https://github.com/langchain-ai/langchain/commit/af2ed47c6f008cdd551f3c0d87db3774c8dfe258",
      "source": "[email protected]",
      "tags": [
        "Patch"
      ]
    },
    {
      "url": "https://github.com/langchain-ai/langchain/pull/36612",
      "source": "[email protected]",
      "tags": [
        "Issue Tracking",
        "Patch"
      ]
    },
    {
      "url": "https://github.com/langchain-ai/langchain/pull/36613",
      "source": "[email protected]",
      "tags": [
        "Issue Tracking",
        "Patch"
      ]
    },
    {
      "url": "https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D0.3.84",
      "source": "[email protected]",
      "tags": [
        "Product",
        "Release Notes"
      ]
    },
    {
      "url": "https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D1.2.28",
      "source": "[email protected]",
      "tags": [
        "Product",
        "Release Notes"
      ]
    },
    {
      "url": "https://github.com/langchain-ai/langchain/security/advisories/GHSA-926x-3r5x-gfhw",
      "source": "[email protected]",
      "tags": [
        "Mitigation",
        "Vendor Advisory"
      ]
    }
  ]
}