{"id":848,"cve":"CVE-2023-37941","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2023-37941","cwe":"CWE-502 Deserialization of Untrusted Data","cwe_number":502,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/502","cvss_score":6.6,"published":"2023-09-06","owasp":"A08 Software and Data Integrity Failures","odc":"Function","cdc":"Incorrect Functionality","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Apache Superset metadata db write access leads to remote code execution","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2023-37941\/","description":"If an attacker gains write access to the Apache Superset metadata database, they could persist a specifically crafted Python object that may lead to remote code execution on Superset's web backend. The Superset metadata db is an 'internal' component that is typically only accessible directly by the system administrator and the superset process itself. Gaining access to that database should be difficult and require significant privileges. This vulnerability impacts Apache Superset versions 1.5.0 up to and including 2.1.0. Users are recommended to upgrade to version 2.1.1 or later.","solution":"Update Apache Superset to version 2.1.1 or later.","affected_component":"Apache Superset","fixed_by_upgrading":true,"vulnerable_code":"import pickle\nimport sqlalchemy\n\n# Assuming `session` is your SQLAlchemy session connected to the Superset metadata database\n\ndef persist_vulnerable_object(obj):\n    # Serialize the object using pickle (vulnerable to arbitrary code execution)\n    data = pickle.dumps(obj)\n    \n    # Store the serialized data in the database\n    new_entry = YourModel(data=data)  # Replace YourModel with your actual model\n    session.add(new_entry)\n    session.commit()\n\n# Example usage\nuser_input = {'key': 'value', '__reduce__': (os.system, ('echo Vulnerable!',))}  # Malicious input\npersist_vulnerable_object(user_input)","patched_code":"import pickle\nimport sqlalchemy\n\n# Assuming `session` is your SQLAlchemy session connected to the Superset metadata database\n\ndef safe_load(data):\n    # Only allow loading of safe types\n    allowed_classes = (dict, list, str, int, float, bool)\n    obj = pickle.loads(data)\n    \n    if not isinstance(obj, allowed_classes):\n        raise ValueError(\"Unsafe object type detected!\")\n    \n    return obj\n\ndef persist_safe_object(obj):\n    # Serialize the object safely\n    safe_data = pickle.dumps(obj)\n    \n    # Store the safe_data in the database\n    new_entry = YourModel(data=safe_data)  # Replace YourModel with your actual model\n    session.add(new_entry)\n    session.commit()\n\n# Example usage\ntry:\n    user_input = {'key': 'value'}  # Replace with actual user input\n    persist_safe_object(user_input)\nexcept Exception as e:\n    print(f\"Error: {e}\")","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[],"references":null}