Skip to content

Conversation

@gaborbernat
Copy link
Contributor

@gaborbernat gaborbernat commented Jan 9, 2026

TOCTOU (Time-of-Check-Time-of-Use) vulnerabilities in directory creation have been fixed to prevent symlink-based attacks.

Two check-then-act patterns in the codebase could be exploited by an attacker with local access:

  1. src/virtualenv/app_data/__init__.py:39-41 checks if the app_data directory exists with os.path.isdir(), then creates it with os.makedirs(). An attacker could create a symlink at the target path between the check and creation, causing virtualenv to write cache files (wheels, Python metadata) to an attacker-controlled location.

  2. src/virtualenv/util/lock.py:19-22 has the same pattern when creating parent directories for lock files. When combined with the first vulnerability, this could allow an attacker to control lock file semantics and bypass concurrent access protections, enabling cache poisoning, information disclosure, lock bypass, and denial of service attacks.

The fix replaces both check-then-act patterns with atomic os.makedirs(..., exist_ok=True) operations. This is atomic at the OS level and eliminates the TOCTOU window, preventing symlink following attacks while maintaining backward compatibility.

Reported by: @tsigouris007

…eation

Use atomic os.makedirs(..., exist_ok=True) operations instead of
check-then-act pattern to prevent symlink-based TOCTOU attacks.

Reported by: tsigouris007

Signed-off-by: Bernát Gábor <[email protected]>
@gaborbernat gaborbernat merged commit dec4cec into pypa:main Jan 9, 2026
51 checks passed
raghotham added a commit to llamastack/llama-stack that referenced this pull request Jan 13, 2026
Vulnerability detected in virtualenv

Affected versions: < [20.36.1]
Fixed in version: [20.36.1]
Severity: MODERATE

Identifiers:
GHSA-597g-3phw-6986
CVE-2026-22702

References:


GHSA-597g-3phw-6986
https://nvd.nist.gov/vuln/detail/CVE-2026-22702
pypa/virtualenv#3013

pypa/virtualenv@dec4cec
GHSA-597g-3phw-6986
franciscojavierarceo pushed a commit to franciscojavierarceo/llama-stack that referenced this pull request Jan 16, 2026
Vulnerability detected in virtualenv

Affected versions: < [20.36.1]
Fixed in version: [20.36.1]
Severity: MODERATE

Identifiers:
GHSA-597g-3phw-6986
CVE-2026-22702

References:


GHSA-597g-3phw-6986
https://nvd.nist.gov/vuln/detail/CVE-2026-22702
pypa/virtualenv#3013

pypa/virtualenv@dec4cec
GHSA-597g-3phw-6986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant