VAITP Dataset

← Back to the dataset

CVE-2026-113724

virtualenv safe_delete follows symlinks, chmods target, making it writable.

  • CVSS 4.5
  • CWE-59
  • Design Defects
  • Local

virtualenv is a tool for creating isolated virtual python environments. Prior to 21.14.9, the safe_delete() deletion error handler responds to a failed removal by reading mode bits with os.lstat(path) and applying owner-write permission with os.chmod(path, …), which follows a symlink. A planted link inside a read-only directory can therefore cause a victim-owned target outside the destination that is initially not writable by the invoking user to become broadly writable before the retry fails, provided that user owns the target and can change its mode. Another account can use the widened mode only if it can traverse the target's parent directories; root does not reach the demonstrated failure path, and the operation does not itself read the target. This issue is fixed in version 21.14.9.

CVSS base score
4.5
Published
2026-10-20
OWASP
A01 Broken Access Control
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Design Defects
Subcategory
Inadequate Error Handling
Accessibility scope
Local
Impact
Privilege Escalation
Affected component
virtualenv
Fixed by upgrading
Yes

Solution

Upgrade virtualenv to version 21.14.9 or later.

Vulnerable code sample

import os
import errno

def safe_delete(path):
    """
    Delete a file or directory, retrying on permission errors.
    """
    try:
        if os.path.isdir(path):
            os.rmdir(path)
        else:
            os.remove(path)
    except OSError as exc:
        # VULNERABLE: follows symlink when fixing mode bits
        if exc.errno == errno.EACCES:
            mode = os.lstat(path).st_mode | 0o200  # add owner write
            os.chmod(path, mode)  # follows symlink – unsafe
            try:
                if os.path.isdir(path):
                    os.rmdir(path)
                else:
                    os.remove(path)
            except OSError:
                pass

Patched code sample

import os
import errno

def safe_delete(path):
    """
    Delete a file or directory, retrying on permission errors.
    """
    try:
        if os.path.isdir(path):
            os.rmdir(path)
        else:
            os.remove(path)
    except OSError as exc:
        # FIX: modify mode without following symlink
        if exc.errno == errno.EACCES:
            fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)
            try:
                mode = os.fstat(fd).st_mode | 0o200  # add owner write
                os.fchmod(fd, mode)  # safe, does not follow symlink
            finally:
                os.close(fd)
            try:
                if os.path.isdir(path):
                    os.rmdir(path)
                else:
                    os.remove(path)
            except OSError:
                pass

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.

Cite this entry

@misc{vaitp:cve2026113724,
  title        = {{virtualenv safe_delete follows symlinks, chmods target, making it writable.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-113724},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-113724/}}
}

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.