{"id":1587,"cve":"CVE-2026-0768","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-0768\/","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":9.8,"published":"2026-01-23","owasp":"A03 Injection","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Command Injection","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Langflow unauthenticated code injection allows remote execution as root.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-0768\/","description":"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.","solution":"Upgrade to Langflow version 0.6.5 or later.","affected_component":"Langflow","fixed_by_upgrading":true,"vulnerable_code":"from fastapi import FastAPI, Body\nfrom typing import Dict\n\napp = FastAPI()\n\n@app.post(\"\/api\/v1\/validate\")\nasync def validate_code(payload: Dict = Body(...)):\n    \"\"\"\n    This is the vulnerable endpoint. It takes a JSON payload with a \"code\" key\n    and executes its content directly.\n    \"\"\"\n    code_string = payload.get(\"code\")\n\n    if not code_string:\n        return {\"detail\": \"No code provided.\"}, 400\n\n    try:\n        # VULNERABILITY: The user-supplied string `code_string` is passed\n        # directly to the `exec` function without any sanitization or\n        # validation. This allows an attacker to execute arbitrary\n        # Python code on the server.\n        exec(code_string)\n        \n        # The response structure is mimicked from a real-world scenario\n        # where the endpoint might return some analysis of the code.\n        return {\"is_valid\": True, \"detail\": \"Code executed successfully.\"}\n    except Exception as e:\n        return {\"is_valid\": False, \"detail\": f\"An error occurred: {str(e)}\"}, 400","patched_code":"import ast\nfrom flask import Flask, request, jsonify\n\n# This example uses the Flask web framework to simulate the API endpoint.\n# The provided CVE-2026-0768 is fictional. This code addresses the principles\n# of the real vulnerability it describes (likely CVE-2024-2734 in Langflow),\n# where user-supplied code was unsafely executed via exec() or eval().\n\napp = Flask(__name__)\n\n@app.route(\"\/validate\", methods=[\"POST\"])\ndef fixed_validate_endpoint():\n    \"\"\"\n    A secure endpoint to validate Python code syntax.\n    This function represents the fix for the described vulnerability.\n    It replaces dangerous code execution with safe syntax tree parsing.\n    \"\"\"\n    try:\n        data = request.get_json()\n        if not data or \"code\" not in data:\n            return jsonify({\"valid\": False, \"error\": \"Request body must be JSON and contain a 'code' field.\"}), 400\n\n        code_to_validate = data[\"code\"]\n\n        if not isinstance(code_to_validate, str):\n             return jsonify({\"valid\": False, \"error\": \"'code' field must be a string.\"}), 400\n\n        # THE FIX:\n        # Instead of using a dangerous function like exec() or eval() on user\n        # input, we safely parse the code into an Abstract Syntax Tree (AST).\n        # The ast.parse() function checks for valid Python syntax without\n        # ever executing the code. If the code is syntactically incorrect,\n        # it will raise a SyntaxError, which is caught below.\n        ast.parse(code_to_validate)\n\n        # If ast.parse() completes without an exception, the code is syntactically valid.\n        return jsonify({\"valid\": True, \"error\": None}), 200\n\n    except SyntaxError as e:\n        # This is the expected and safe outcome for syntactically invalid Python code.\n        return jsonify({\"valid\": False, \"error\": f\"Syntax Error: {e}\"}), 400\n    except Exception as e:\n        # Catch any other unexpected errors during processing.\n        return jsonify({\"valid\": False, \"error\": f\"An unexpected error occurred: {str(e)}\"}), 500\n\nif __name__ == '__main__':\n    # To run this demonstration:\n    # 1. pip install Flask\n    # 2. python <filename>.py\n    # 3. Use a tool like curl to test the endpoint.\n\n    # Example of a safe, valid request:\n    # 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\n    # Expected output: {\"valid\": true, \"error\": null}\n\n    # Example of a malicious payload that is safely rejected as valid syntax:\n    # curl -X POST -H \"Content-Type: application\/json\" -d '{\"code\": \"__import__(\\\"os\\\").system(\\\"echo pwned\\\")\"}' http:\/\/127.0.0.1:5000\/validate\n    # Expected output: {\"valid\": true, \"error\": null} -> Note: The code is not executed, only validated.\n\n    # Example of a syntactically invalid request that is safely rejected:\n    # curl -X POST -H \"Content-Type: application\/json\" -d '{\"code\": \"print(hello\"}' http:\/\/127.0.0.1:5000\/validate\n    # Expected output: {\"valid\": false, \"error\": \"Syntax Error: ...\"}\n\n    app.run(port=5000)","payload_needed":true,"payload":"```python\n__import__('os').system('id')\n```","payload_status":"available","published_fix":[],"references":null}