CVE-2026-51886
Code injection in /api/v1/validate/code allows authenticated users to exec arbitrary Python.
- CVSS 9.8
- CWE-94
- Input Validation and Sanitization
- Remote
langflow-ai langflow v1.9.3 is affected by: Code Injection. The impact is: execute arbitrary code (remote). The component is: src/backend/base/langflow/api/v1/validate.py:validate-post_validate_code-a-real-authenticated-http-post-to-api-v1. The attack vector is: Attack surface: HTTP or browser-backed service path. A public-facing route accepts raw Python source and forwards it into a server-side compile/exec validation path without any visible entitlement guard. ¶¶ A weakness has been identified in langflow-ai langflow up to 1.9.3. langflow contains a code injection vulnerability in validate-post_validate_code-a-real-authenticated-http-post-to-api-v1 (src/backend/base/langflow/api/v1/validate.py:13). An authenticated attacker can execute arbitrary Python code on the server by submitting malicious code to the /api/v1/validate/code endpoint, which directly executes user-supplied code without sandboxing or security controls.
- CWE
- CWE-94
- CVSS base score
- 9.8
- Published
- 2026-10-01
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- langflow
Solution
Upgrade langflow to version 1.9.4 or later, which patches the code‑injection flaw in /api/v1/validate/code.
Vulnerable code sample
import ast
from fastapi import APIRouter, Request, HTTPException
router = APIRouter()
@router.post("/api/v1/validate/code")
async def validate_code(request: Request):
"""
Accept raw Python source, compile and exec it to validate syntax.
"""
payload = await request.json()
source = payload.get("code", "")
# VULNERABLE: directly exec user‑supplied code
try:
compiled = compile(source, "<user_code>", "exec")
exec(compiled, {})
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc))
return {"status": "ok"}Patched code sample
import ast
import sys
from fastapi import APIRouter, Request, HTTPException
router = APIRouter()
@router.post("/api/v1/validate/code")
async def validate_code(request: Request):
"""
Accept raw Python source, parse it safely without executing.
"""
payload = await request.json()
source = payload.get("code", "")
# FIX: parse only, no execution
try:
# Use ast.parse to ensure syntax is valid; reject any code containing exec/eval
tree = ast.parse(source, mode="exec")
for node in ast.walk(tree):
if isinstance(node, (ast.Exec, ast.Call)) and getattr(node, "func", None) and getattr(node.func, "id", None) in {"exec", "eval", "compile", "open", "input"}:
raise ValueError("Disallowed function in code")
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc))
return {"status": "ok"}Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- fix(security): do not execute code in validate_code (GHSA-2wcq-pvw2-xh7v) (#13696) (langflow-ai/langflow)
src/lfx/src/lfx/custom/validate.py,src/lfx/src/lfx/custom/validate.py · validate_code
Cite this entry
@misc{vaitp:cve202651886,
title = {{Code injection in /api/v1/validate/code allows authenticated users to exec arbitrary Python.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-51886},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-51886/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
