VAITP Dataset

← Back to the dataset

CVE-2022-21699

IPython: Cross-user code execution via file mismanagement

  • CVSS 8.8
  • CWE-269
  • Authentication, Authorization, and Session Management
  • Local

IPython (Interactive Python) is a command shell for interactive computing in multiple programming languages, originally developed for the Python programming language. Affected versions are subject to an arbitrary code execution vulnerability achieved by not properly managing cross user temporary files. This vulnerability allows one user to run code as another on the same machine. All users are advised to upgrade.

CVSS base score
8.8
Published
2022-01-19
OWASP
A01 Broken Access Control
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Authentication, Authorization, and Session Management
Subcategory
Privilege Escalation
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
IPython
Fixed by upgrading
Yes

Solution

Update IPython to the latest version.

Vulnerable code sample

import tempfile

def insecure_temp_file():
    # Create a temporary file without proper permission management
    temp_file = tempfile.NamedTemporaryFile(delete=False)
    return temp_file.name

# Example usage
temp_file_path = insecure_temp_file()
with open(temp_file_path, 'w') as f:
    f.write("Insecure temporary file content.")

# Note: This file can be accessed by other users on the system before it's deleted.

Patched code sample

import tempfile
import os
import stat

def secure_temp_file():
    # Create a secure temporary file with restricted permissions
    temp_file = tempfile.NamedTemporaryFile(delete=False)
    os.chmod(temp_file.name, stat.S_IRUSR | stat.S_IWUSR)  # Only allow the owner to read and write
    return temp_file.name

# Example usage
temp_file_path = secure_temp_file()
with open(temp_file_path, 'w') as f:
    f.write("Secure temporary file content.")

# Ensure to clean up the temporary file after use
os.remove(temp_file_path)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • FIX CVE-2022-21699 (ipython/ipython)
    IPython/core/application.py · BaseIPythonApplication._config_file_paths_default, IPython/core/profileapp.py · ProfileList.list_profile_dirs, IPython/core/profiledir.py · ProfileDir.find_profile_dir_by_name, IPython/__init__.py

Cite this entry

@misc{vaitp:cve202221699,
  title        = {{IPython: Cross-user code execution via file mismanagement}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-21699},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-21699/}}
}

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.