{"id":1137,"cve":"CVE-2024-45848","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2024-45848\/","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":8.8,"published":"2024-09-12","owasp":"A03 Injection","odc":"Function","cdc":"Incorrect Functionality","category":"Input Validation and Sanitization","subcategory":"SQL Injection","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Arbitrary code execution in MindsDB with crafted INSERT queries.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2024-45848\/","description":"An arbitrary code execution vulnerability exists in versions 23.12.4.0 up to 24.7.4.1 of the MindsDB platform, when the ChromaDB integration is installed on the server. If a specially crafted \u2018INSERT\u2019 query containing Python code is run against a database created with the ChromaDB engine, the code will be passed to an eval function and executed on the server.","solution":"Upgrade to MindsDB version 24.7.4.2 or later.","affected_component":"MindsDB","fixed_by_upgrading":false,"vulnerable_code":"def execute_query(db_connection, query):\n    \"\"\"Vulnerable function that demonstrates the security issue.\"\"\"\n    if \"INSERT\" in query:\n        eval(query)\n    else:\n        raise ValueError(\"Invalid query type\")\n\nconn = None\nexecute_query(conn, \"INSERT INTO users (name) VALUES ('Alice'); os.system('whoami')\")","patched_code":"import re\n\ndef execute_query(db_connection, query):\n    \"\"\"Secure function that fixes the vulnerability.\"\"\"\n    # SECURE: This version prevents command injection\n    if not isinstance(query, str):\n        raise ValueError(\"Query must be a string\")\n\n    if any(bad_keyword in query.lower() for bad_keyword in ['os.', 'system', ';', '--', '\/*', '*\/']):\n        raise ValueError(\"Invalid query detected\")\n\n    insert_pattern = re.compile(r\"^INSERT INTO \\w+ \\(\\w+(, \\w+)*\\) VALUES \\(.+\\)$\", re.IGNORECASE)\n    if insert_pattern.match(query):\n        print(f\"Executing query: {query}\")\n    else:\n        raise ValueError(\"Invalid query type or format\")\n\n\nconn = None\ntry:\n    execute_query(conn, \"INSERT INTO users (name) VALUES ('Alice'); os.system('whoami')\")\nexcept ValueError as e:\n    print(f\"Error: {e}\")\n","payload_needed":true,"payload":"```python\n\"__import__('os').system('whoami')\"\n```","payload_status":"available","published_fix":[{"repository":"mindsdb\/mindsdb","commit_url":"https:\/\/github.com\/mindsdb\/mindsdb\/commit\/11a4db792ad36cf704f7307c7602128b17752c80","commit_subject":"Replace eval with literal_eval (#9533)","units":[{"file":"mindsdb\/integrations\/handlers\/chromadb_handler\/chromadb_handler.py","function":null},{"file":"mindsdb\/integrations\/handlers\/chromadb_handler\/chromadb_handler.py","function":"ChromaDBHandler.insert"},{"file":"mindsdb\/integrations\/handlers\/sharepoint_handler\/sharepoint_api.py","function":null},{"file":"mindsdb\/integrations\/handlers\/sharepoint_handler\/sharepoint_api.py","function":"SharepointAPI.create_an_item"},{"file":"mindsdb\/integrations\/handlers\/sharepoint_handler\/sharepoint_api.py","function":"SharepointAPI.create_a_list"},{"file":"mindsdb\/integrations\/handlers\/sharepoint_handler\/sharepoint_api.py","function":"SharepointAPI.create_a_site_column"},{"file":"mindsdb\/integrations\/handlers\/weaviate_handler\/weaviate_handler.py","function":null},{"file":"mindsdb\/integrations\/handlers\/weaviate_handler\/weaviate_handler.py","function":"WeaviateDBHandler.select"},{"file":"mindsdb\/integrations\/libs\/vectordatabase_handler.py","function":"VectorStoreHandler._dispatch_update"}]}],"references":null}