CVE-2026-0768
Langflow unauthenticated code injection allows remote execution as root.
- CVSS 9.8
- CWE-94
- Input Validation and Sanitization
- Remote
Langflow code Code Injection Remote Code Execution Vulnerability. This vulnerability allows remote attackers to execute arbitrary code on affected installations of Langflow. Authentication is not required to exploit this vulnerability. The specific flaw exists within the handling of the code parameter provided to the validate endpoint. The issue results from the lack of proper validation of a user-supplied string before using it to execute Python code. An attacker can leverage this vulnerability to execute code in the context of root. . Was ZDI-CAN-27322.
- CWE
- CWE-94
- CVSS base score
- 9.8
- Published
- 2026-01-23
- 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
- Fixed by upgrading
- Yes
Solution
Upgrade to Langflow version 0.6.5 or later.
Vulnerable code sample
from fastapi import FastAPI, Body
from typing import Dict
app = FastAPI()
@app.post("/api/v1/validate")
async def validate_code(payload: Dict = Body(...)):
"""
This is the vulnerable endpoint. It takes a JSON payload with a "code" key
and executes its content directly.
"""
code_string = payload.get("code")
if not code_string:
return {"detail": "No code provided."}, 400
try:
# VULNERABILITY: The user-supplied string `code_string` is passed
# directly to the `exec` function without any sanitization or
# validation. This allows an attacker to execute arbitrary
# Python code on the server.
exec(code_string)
# The response structure is mimicked from a real-world scenario
# where the endpoint might return some analysis of the code.
return {"is_valid": True, "detail": "Code executed successfully."}
except Exception as e:
return {"is_valid": False, "detail": f"An error occurred: {str(e)}"}, 400Patched code sample
import ast
from flask import Flask, request, jsonify
# This example uses the Flask web framework to simulate the API endpoint.
# The provided CVE-2026-0768 is fictional. This code addresses the principles
# of the real vulnerability it describes (likely CVE-2024-2734 in Langflow),
# where user-supplied code was unsafely executed via exec() or eval().
app = Flask(__name__)
@app.route("/validate", methods=["POST"])
def fixed_validate_endpoint():
"""
A secure endpoint to validate Python code syntax.
This function represents the fix for the described vulnerability.
It replaces dangerous code execution with safe syntax tree parsing.
"""
try:
data = request.get_json()
if not data or "code" not in data:
return jsonify({"valid": False, "error": "Request body must be JSON and contain a 'code' field."}), 400
code_to_validate = data["code"]
if not isinstance(code_to_validate, str):
return jsonify({"valid": False, "error": "'code' field must be a string."}), 400
# THE FIX:
# Instead of using a dangerous function like exec() or eval() on user
# input, we safely parse the code into an Abstract Syntax Tree (AST).
# The ast.parse() function checks for valid Python syntax without
# ever executing the code. If the code is syntactically incorrect,
# it will raise a SyntaxError, which is caught below.
ast.parse(code_to_validate)
# If ast.parse() completes without an exception, the code is syntactically valid.
return jsonify({"valid": True, "error": None}), 200
except SyntaxError as e:
# This is the expected and safe outcome for syntactically invalid Python code.
return jsonify({"valid": False, "error": f"Syntax Error: {e}"}), 400
except Exception as e:
# Catch any other unexpected errors during processing.
return jsonify({"valid": False, "error": f"An unexpected error occurred: {str(e)}"}), 500
if __name__ == '__main__':
# To run this demonstration:
# 1. pip install Flask
# 2. python <filename>.py
# 3. Use a tool like curl to test the endpoint.
# Example of a safe, valid request:
# curl -X POST -H "Content-Type: application/json" -d '{"code": "import os\n\ndef my_func():\n return True"}' http://127.0.0.1:5000/validate
# Expected output: {"valid": true, "error": null}
# Example of a malicious payload that is safely rejected as valid syntax:
# curl -X POST -H "Content-Type: application/json" -d '{"code": "__import__(\"os\").system(\"echo pwned\")"}' http://127.0.0.1:5000/validate
# Expected output: {"valid": true, "error": null} -> Note: The code is not executed, only validated.
# Example of a syntactically invalid request that is safely rejected:
# curl -X POST -H "Content-Type: application/json" -d '{"code": "print(hello"}' http://127.0.0.1:5000/validate
# Expected output: {"valid": false, "error": "Syntax Error: ..."}
app.run(port=5000)Payload
__import__('os').system('id')
Cite this entry
@misc{vaitp:cve20260768,
title = {{Langflow unauthenticated code injection allows remote execution as root.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-0768},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-0768/}}
}
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 ::
