VAITP Dataset

← Back to the dataset

CVE-2020-11073

Malicious .venv file in Autoswitch Python Virtualenv (pre-1.16.0) allows code execution

  • CVSS 7.8
  • CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • Input Validation and Sanitization
  • Local

In Autoswitch Python Virtualenv before version 0.16.0, a user who enters a directory with a malicious `.venv` file could run arbitrary code without any user interaction. This is fixed in version: 1.16.0

CVSS base score
7.8
Published
2020-05-13
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
Autoswitch
Fixed by upgrading
Yes

Solution

Update Autoswitch Python Virtualenv to version 1.16.0 or higher.

Vulnerable code sample

import os

def activate_virtualenv():
    current_dir = os.getcwd()
    venv_file = os.path.join(current_dir, '.venv')

    # Vulnerable code: directly executing the .venv file if it exists
    if os.path.isfile(venv_file):
        print("Activating virtual environment from .venv file...")
        with open(venv_file) as f:
            exec(f.read(), dict(__file__=venv_file))

    # Proceed to activate the virtual environment
    venv_path = os.path.join(current_dir, 'venv')
    if os.path.isdir(venv_path):
        activate_script = os.path.join(venv_path, 'bin', 'activate_this.py')
        if os.path.isfile(activate_script):
            with open(activate_script) as f:
                exec(f.read(), dict(__file__=activate_script))
    else:
        print("No virtual environment found.")

if __name__ == "__main__":
    activate_virtualenv()

Patched code sample

import os
import sys
import subprocess

def activate_virtualenv():
    current_dir = os.getcwd()
    venv_file = os.path.join(current_dir, '.venv')

    if os.path.isfile(venv_file):
        print("Warning: .venv file detected, skipping activation to prevent potential security risks.")
        return

    # Proceed to activate the virtual environment if no .venv file is found
    venv_path = os.path.join(current_dir, 'venv')
    if os.path.isdir(venv_path):
        activate_script = os.path.join(venv_path, 'bin', 'activate_this.py')
        if os.path.isfile(activate_script):
            with open(activate_script) as f:
                exec(f.read(), dict(__file__=activate_script))
        else:
            print("No activation script found.")
    else:
        print("No virtual environment found.")

if __name__ == "__main__":
    activate_virtualenv()

Cite this entry

@misc{vaitp:cve202011073,
  title        = {{Malicious .venv file in Autoswitch Python Virtualenv (pre-1.16.0) allows code execution}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2020},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2020-11073},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-11073/}}
}

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.