CVE-2025-71176 Overview
CVE-2025-71176 is a race condition vulnerability affecting pytest through version 9.0.2 on UNIX systems. The vulnerability exists due to the testing framework's reliance on predictable temporary directory paths following the /tmp/pytest-of-{user} naming pattern. This insecure temporary file handling allows local users to cause a denial of service or potentially escalate privileges through symlink attacks or directory manipulation.
Critical Impact
Local attackers can exploit predictable temporary directory paths to disrupt pytest test execution or potentially gain elevated privileges through symlink attacks targeting the /tmp/pytest-of-{user} directories.
Affected Products
- pytest through version 9.0.2 on UNIX systems
- Applications and CI/CD pipelines using affected pytest versions
- Development environments running pytest with default temporary directory configurations
Discovery Timeline
- 2026-01-22 - CVE CVE-2025-71176 published to NVD
- 2026-01-22 - Last updated in NVD database
Technical Details for CVE-2025-71176
Vulnerability Analysis
This vulnerability falls under CWE-379 (Creation of Temporary File in Directory with Insecure Permissions). The core issue stems from pytest's use of predictable temporary directory paths on UNIX systems. When pytest executes tests, it creates temporary directories following a static naming convention that incorporates the username running the tests. This predictability creates a window of opportunity for local attackers to preemptively create these directories or establish symbolic links before pytest initializes them.
The exploitation impact is twofold: denial of service can occur when an attacker prevents pytest from creating or accessing its required temporary directories, disrupting test execution. More concerning is the potential for privilege escalation through symlink attacks, where an attacker could redirect pytest's file operations to sensitive system locations.
Root Cause
The root cause is pytest's reliance on a predictable naming pattern for temporary directories without adequate validation. The framework uses /tmp/pytest-of-{user} as the base path for temporary test artifacts, where {user} is derived from the current system username. This deterministic approach violates secure coding practices for temporary file handling, which recommend using randomized, unpredictable paths or secure directory creation functions that prevent race conditions.
Attack Vector
The attack requires local access to the target system. An attacker with knowledge of which user accounts run pytest can preemptively create malicious symbolic links or directories at the expected temporary path locations. When pytest subsequently attempts to use these paths, the attacker can either cause the operation to fail (denial of service) or redirect file operations to unintended locations (potential privilege escalation). This Time-of-Check Time-of-Use (TOCTOU) race condition is particularly relevant in multi-user environments and shared CI/CD infrastructure.
The attack can be executed by creating a symbolic link at /tmp/pytest-of-{targetuser} pointing to a sensitive directory before the legitimate user runs pytest. When pytest creates files in what it believes is its temporary directory, those files may instead be written to the symlink target location.
Detection Methods for CVE-2025-71176
Indicators of Compromise
- Unexpected symbolic links present at /tmp/pytest-of-* paths pointing to non-standard locations
- Directory ownership anomalies where pytest temporary directories are owned by unexpected users
- Presence of pre-created /tmp/pytest-of-{user} directories with suspicious permissions or timestamps
- File system events showing rapid creation/deletion of pytest temporary directories by non-pytest processes
Detection Strategies
- Monitor file system activity in /tmp/ for creation of pytest-of-* directories by users other than the expected pytest runners
- Implement integrity checking for temporary directory paths before pytest execution in CI/CD pipelines
- Audit symbolic link creation events targeting pytest temporary directory patterns
- Use process monitoring to detect attempts to access or modify pytest temporary directories by unauthorized processes
Monitoring Recommendations
- Configure file integrity monitoring (FIM) rules for the /tmp/ directory to alert on suspicious pytest-related directory activity
- Implement audit rules using auditd or similar tools to track symlink and mkdir system calls targeting /tmp/pytest-of-* paths
- Review system logs for failed pytest executions that may indicate exploitation attempts
- In shared environments, monitor for users creating directories matching other users' pytest temporary path patterns
How to Mitigate CVE-2025-71176
Immediate Actions Required
- Upgrade pytest to a patched version when available from the pytest development team
- Configure pytest to use a non-default, secure temporary directory location with restricted permissions
- In shared or multi-user environments, implement filesystem protections such as sticky bits and user-private /tmp directories
- Review CI/CD pipeline configurations to ensure pytest runs in isolated environments with proper filesystem sandboxing
Patch Information
As of the last update, users should monitor the pytest GitHub Issues for official patches and version updates addressing this vulnerability. The security discussion is also tracked on the OpenWall Security Mailing List. Organizations should upgrade to the latest pytest version once a fix is released.
Workarounds
- Configure the PYTEST_DEBUG_TEMPROOT environment variable to use a secure, user-specific directory with restricted permissions instead of the default /tmp location
- Use containerization or virtualization to isolate pytest execution environments, preventing cross-user temporary directory attacks
- Implement filesystem namespacing in CI/CD environments to give each pytest instance its own private /tmp directory
- On Linux systems, enable per-user temporary directories using pam_namespace or similar mechanisms
# Configuration example
# Set a secure custom temporary directory for pytest
export PYTEST_DEBUG_TEMPROOT="/home/$USER/.pytest_tmp"
mkdir -p "$PYTEST_DEBUG_TEMPROOT"
chmod 700 "$PYTEST_DEBUG_TEMPROOT"
# Alternatively, use tmpfs with restricted permissions
# Add to /etc/fstab for persistent private tmp:
# tmpfs /home/user/.pytest_tmp tmpfs mode=0700,uid=1000,gid=1000 0 0
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


