Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB
CVE-2026-113721 Overview
CVE-2026-113721 is a symlink-following vulnerability in virtualenv, the widely used tool for creating isolated Python environments. Versions prior to 21.14.9 fail to replace existing symbolic or hard links before writing generated files such as pyvenv.cfg and activation scripts. A local attacker with an account on the same system can plant links inside the destination directory before environment creation. The invoking user then unknowingly overwrites files outside the requested tree with virtualenv-generated content and their own permissions. The issue is tracked under [CWE-59: Link Following] and is fixed in virtualenv21.14.9.
Critical Impact
A local account can redirect virtualenv file writes through pre-planted symlinks, overwriting arbitrary files writable by the invoking user.
Affected Products
- pypa/virtualenv versions prior to 21.14.9
- Python environments created by vulnerable virtualenv releases
- Multi-user Linux and Windows systems where virtualenv runs under a higher-privileged account
Discovery Timeline
- 2026-10-20 - CVE-2026-113721 published to the National Vulnerability Database
- 2026-10-22 - Last updated in NVD database
- Fix release - virtualenv21.14.9 published on GitHub with patch commit d25f286
Technical Details for CVE-2026-113721
Vulnerability Analysis
The flaw sits in two code paths used during environment creation. ViaTemplateActivator._generate() removes an existing output file only when Path.exists() returns true. A dangling symlink does not satisfy Path.exists(), so the link survives and the subsequent write follows it to the target. Separately, PyEnvCfg.write() opens pyvenv.cfg without first unlinking an existing symbolic or hard link, so the open operation resolves through the link.
When another local account pre-populates the destination with crafted links, virtualenv writes generated content through them. The resulting files land outside the requested tree under the invoking user's permissions. This is a classic link-following weakness categorized under [CWE-59].
Root Cause
The root cause is missing symlink and hardlink replacement before file writes. virtualenv assumed any entry in the destination was either absent or a regular file. It did not call os.unlink() or an equivalent unlink then open with O_EXCL sequence before generating activation scripts, pyvenv.cfg, import hooks, and seed launchers.
Attack Vector
Exploitation requires local access and the ability to write into the destination directory before virtualenv runs. The attacker places a symbolic or hard link whose name matches a file virtualenv will generate. When the environment owner invokes virtualenv, the generated content is redirected to the link target. The attacker cannot choose arbitrary content, but can overwrite files writable by the invoking user with constrained, virtualenv-generated data.
The security advisory notes that the destination parent must remain under the environment owner's control during creation. Concurrent replacement of the parent directory is treated as a separate concern.
import shlex
import sys
from abc import ABC, abstractmethod
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Final
+
+from virtualenv.util.path import write_file
from .activator import Activator
Source: GitHub patch commit d25f286 — src/virtualenv/activation/via_template.py. The patch introduces a dedicated write_file helper that replaces existing links before writing generated content.
Detection Methods for CVE-2026-113721
Indicators of Compromise
- Unexpected symbolic or hard links inside a target virtualenv destination directory prior to environment creation.
- Files such as pyvenv.cfg, activate, activate.ps1, or seed launchers whose contents appear in locations outside any Python environment tree.
- virtualenv runs completing successfully but producing environments where activation scripts resolve to paths outside the expected prefix.
Detection Strategies
- Audit filesystem events on shared build servers and CI runners for openat() or CreateFile calls that traverse symlinks when invoked by virtualenv.
- Flag any pre-existing non-regular files inside directories passed as virtualenv destinations in CI pipelines and developer workstations.
- Compare installed virtualenv versions across hosts against the fixed version 21.14.9 using software inventory data.
Monitoring Recommendations
- Monitor process creation events where virtualenv or python -m virtualenv is invoked, correlating with filesystem writes outside the stated destination path.
- Track creation of symlinks inside world-writable or group-writable directories that are later used as virtualenv targets.
- Review build system logs for warnings or errors related to activation script generation that may indicate link redirection.
How to Mitigate CVE-2026-113721
Immediate Actions Required
- Upgrade virtualenv to version 21.14.9 or later on all developer workstations, build servers, and container images.
- Audit shared systems for existing dangling or suspicious links in directories used as virtualenv destinations.
- Ensure that virtualenv is never run with the destination parent directory writable by lower-privileged accounts.
Patch Information
The fix is published in virtualenv 21.14.9 and implemented in pull request #3431. The patch replaces existing symbolic and hard links before writing environment configuration, activation scripts, import hooks, and seed launchers. It also replaces executable-directory symlinks and Windows junctions with real directories before recreating environments. Full technical details are available in GitHub Security Advisory GHSA-558c-9hv2-4prj.
Replace generated file links (#3431):
- Replace existing symbolic and hard links when writing environment
configuration, activation scripts, import hooks, and seed launchers.
- Create generated text files exclusively so a replacement link cannot
redirect the final file open.
- Before recreating an environment with the stdlib venv creator,
replace executable-directory symlinks and Windows junctions with
real directories.
- Remove symbolic and hard links inside that directory before creating
interpreter files, including when switching from symlinks to copies.
Source: GitHub patch commit d25f286 — docs/changelog/3431.bugfix.rst.
Workarounds
- Create virtualenv destinations in parent directories owned exclusively by the invoking user with mode 0700.
- Avoid running virtualenv with destinations located in world-writable paths such as /tmp on multi-user hosts.
- Pin virtualenv>=21.14.9 in requirements files and CI tooling to prevent regression to vulnerable releases.
# Upgrade virtualenv to the fixed version
python -m pip install --upgrade 'virtualenv>=21.14.9'
# Verify installed version
python -m virtualenv --version
# Create environments under a user-owned, restricted parent directory
install -d -m 0700 "$HOME/venvs"
python -m virtualenv "$HOME/venvs/myproject"
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB

