{"id":247,"cve":"CVE-2020-1192","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2020-1192","cwe":"CWE-94 Improper Control of Generation of Code ('Code Injection')","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":7.8,"published":"2020-05-21","owasp":"A03 Injection","odc":"Function","cdc":"Incorrect Functionality","category":"Configuration Issues","subcategory":"Server-Side Request Forgery (SSRF)","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Visual Studio Code Python extension had a remote code execution vulnerability when loading workspace settings from a notebook file","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2020-1192\/","description":"A remote code execution vulnerability exists in Visual Studio Code when the Python extension loads workspace settings from a notebook file, aka 'Visual Studio Code Python Extension Remote Code Execution Vulnerability'. This CVE ID is unique from CVE-2020-1171.","solution":"Update Visual Studio Code Python extension to the latest version.","affected_component":"Visual Studio Code","fixed_by_upgrading":true,"vulnerable_code":"import json\n\ndef load_notebook_settings(file_path):\n    # Load the notebook file without any validation\n    with open(file_path, 'r') as file:\n        notebook_data = json.load(file)\n\n    # Directly process the notebook settings, which may include untrusted code\n    settings = notebook_data.get('metadata', {})\n    \n    # Potentially unsafe execution of code from the notebook\n    exec(settings.get('code', ''))\n\n# Example usage\nload_notebook_settings('example_notebook.ipynb')","patched_code":"import json\nimport os\n\ndef load_notebook_settings(file_path):\n    # Ensure the file is a trusted notebook file\n    if not file_path.endswith('.ipynb'):\n        raise ValueError(\"Invalid file type. Only .ipynb files are allowed.\")\n\n    # Load the notebook file safely\n    with open(file_path, 'r') as file:\n        notebook_data = json.load(file)\n\n    # Validate the content of the notebook before processing\n    if 'cells' not in notebook_data:\n        raise ValueError(\"Invalid notebook structure. 'cells' key is missing.\")\n\n    # Process notebook settings safely\n    settings = {}\n    for cell in notebook_data['cells']:\n        if 'metadata' in cell and 'trusted' in cell['metadata']:\n            if cell['metadata']['trusted']:\n                # Only process trusted cells\n                settings.update(cell.get('metadata', {}))\n\n    return settings\n\n# Example usage\ntry:\n    settings = load_notebook_settings('example_notebook.ipynb')\n    print(\"Loaded settings:\", settings)\nexcept Exception as e:\n    print(\"Error:\", e)","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[],"references":null}