VAITP Dataset

← Back to the dataset

CVE-2020-17163

VS Code Python extension RCE

  • CVSS 7.8
  • CWE-94 Improper Control of Generation of Code ('Code Injection')
  • Input Validation and Sanitization
  • Remote

Visual Studio Code Python Extension, before (<) 2020.9.2, Remote Code Execution Vulnerability

CVSS base score
7.8
Published
2023-12-29
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Fixed by upgrading
Yes

Solution

Update Visual Studio Code Python Extension to version 2020.9.2 or later

Vulnerable code sample

import os

def execute_command(user_input):
    """Vulnerable function that demonstrates the security issue."""
    os.system(f'python {user_input}')

user_input = 'script1.py'
output = execute_command(user_input)

Patched code sample

import os
import subprocess

def execute_command(user_input):
    """Secure function that fixes the vulnerability."""
    if not check_input(user_input):
        raise ValueError("Unsafe input detected!")

    result = subprocess.run(['python', user_input], capture_output=True, text=True)
    return result.stdout

def check_input(user_input):
    """Secure function that fixes the vulnerability."""
    allowed_commands = {'script1.py', 'script2.py'}
    return user_input in allowed_commands

try:
    user_input = 'script1.py'
    output = execute_command(user_input)
    print(output)
except ValueError as e:
    print(e)

Cite this entry

@misc{vaitp:cve202017163,
  title        = {{VS Code Python extension RCE}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2023},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-17163},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-17163/}}
}
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 ::