VAITP Dataset

← Back to the dataset

CVE-2020-1192

Visual Studio Code Python extension had a remote code execution vulnerability when loading workspace settings from a notebook file

  • CVSS 7.8
  • CWE-94 Improper Control of Generation of Code ('Code Injection')
  • Configuration Issues
  • Remote

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.

CVSS base score
7.8
Published
2020-05-21
OWASP
A03 Injection
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Configuration Issues
Subcategory
Server-Side Request Forgery (SSRF)
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Visual Studio Code
Fixed by upgrading
Yes

Solution

Update Visual Studio Code Python extension to the latest version.

Vulnerable code sample

import json

def load_notebook_settings(file_path):
    # Load the notebook file without any validation
    with open(file_path, 'r') as file:
        notebook_data = json.load(file)

    # Directly process the notebook settings, which may include untrusted code
    settings = notebook_data.get('metadata', {})
    
    # Potentially unsafe execution of code from the notebook
    exec(settings.get('code', ''))

# Example usage
load_notebook_settings('example_notebook.ipynb')

Patched code sample

import json
import os

def load_notebook_settings(file_path):
    # Ensure the file is a trusted notebook file
    if not file_path.endswith('.ipynb'):
        raise ValueError("Invalid file type. Only .ipynb files are allowed.")

    # Load the notebook file safely
    with open(file_path, 'r') as file:
        notebook_data = json.load(file)

    # Validate the content of the notebook before processing
    if 'cells' not in notebook_data:
        raise ValueError("Invalid notebook structure. 'cells' key is missing.")

    # Process notebook settings safely
    settings = {}
    for cell in notebook_data['cells']:
        if 'metadata' in cell and 'trusted' in cell['metadata']:
            if cell['metadata']['trusted']:
                # Only process trusted cells
                settings.update(cell.get('metadata', {}))

    return settings

# Example usage
try:
    settings = load_notebook_settings('example_notebook.ipynb')
    print("Loaded settings:", settings)
except Exception as e:
    print("Error:", e)

Cite this entry

@misc{vaitp:cve20201192,
  title        = {{Visual Studio Code Python extension had a remote code execution vulnerability when loading workspace settings from a notebook file}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2020},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-1192},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-1192/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.