Summary
The Python wheel command-line tool's unpack functionality mishandles file permissions after extraction, trusting file names from the archive header instead of the sanitized paths actually written to disk.
A crafted wheel archive can cause wheel unpack to change permissions on arbitrary system files (such as /etc/passwd, SSH keys, or configuration files), potentially enabling privilege escalation or execution of modified scripts.
Affected context
This vulnerability affects environments where:
- The Python
wheeltool (versions 0.40.0 through 0.46.1) is installed and used to unpack wheel files. - Wheel archives can originate from sources that are not fully trusted, such as public package indexes, internal artifact stores, or third-party suppliers.
- The unpack operation runs on hosts that possess sensitive files whose permissions, if loosened, could weaken system or application security.
The issue arises specifically in the unpack function, where post-extraction permission changes are applied using archive-provided file names rather than the sanitized extraction paths.
Exploit preconditions
- Attack surface: The
wheel unpackcommand-line interface and any tooling that invokes it on provided wheel files. - Required access: Ability to supply or influence wheel files processed by a vulnerable
wheelinstallation (e.g., via a dependency, artifact upload, or social engineering). - Execution context: The command must be run in an environment that contains sensitive files accessible by the unpacking process and whose permissions are valuable to an attacker (such as system configuration files or private keys).
- Trigger point: Running
wheel unpackon a maliciously crafted wheel file that includes archive metadata designed to point chmod operations at attacker-chosen paths. - Why exploitation is possible: The unpack logic decouples path sanitization and permission application, trusting the original archive header filename when calling
chmod, allowing permission changes on paths that were never created or sanitized during extraction.
Why this happens
The core issue stems from a mismatch between sanitized extraction paths and trusted archive metadata used for permission changes.
During extraction, secure tooling typically normalizes and sanitizes paths to avoid directory traversal and other filesystem abuses (CWE-22). However, in this case, the code that sets file permissions after extraction relies directly on the original filename string from the wheel archive header rather than the actual, sanitized filesystem path produced during extraction.
This design flaw aligns with:
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because attacker-controlled path data from the archive is effectively allowed to target arbitrary locations on the filesystem for chmod operations.
- CWE-732: Incorrect Permission Assignment for Critical Resource, because the vulnerable code can assign overly permissive or attacker-chosen permissions to files that were not intended to be modified.
Abstractly, the insecure pattern is "using attacker-supplied path metadata for security-sensitive filesystem operations (chmod) after a separate, safer extraction step," rather than carrying forward the validated path information.
Potential impact
- Permissions of critical system files (e.g.,
/etc/passwd,/etc/shadowwhere accessible, SSH keys, or application secrets) may be loosened, allowing unintended read or write access. - Attackers may gain the ability to modify scripts or binaries that are later executed by privileged users or services, potentially leading to arbitrary code execution.
- Service accounts and application processes could gain access to configuration or credential files they were not meant to read.
- Security boundaries based on file ownership and mode bits (e.g., world-readable, world-writable) can be eroded, facilitating privilege escalation or lateral movement on the host.
- Audit trails and integrity assumptions for deployment or build directories can be undermined if permissions are silently altered during unpack.
General mitigation guidance
Effective mitigation centers on decoupling untrusted metadata from security-sensitive filesystem operations and tightening permission handling:
- Ensure that any post-extraction operations (including chmod) operate only on validated, canonicalized paths returned by the extraction routine, not the original archive header names.
- Introduce a path canonicalization and policy layer that:
- Resolves symlinks and relative segments (e.g.,
..). - Confirms the target path resides within a designated extraction root.
- Rejects or ignores any path that attempts to escape that root.
- Apply least-privilege defaults when setting permissions:
- Use conservative file modes and avoid making files more permissive than necessary.
- Disallow changing permissions on files outside controlled extraction directories.
- Treat archive metadata as untrusted input:
- Validate filenames and reject path patterns that are not expected in wheel archives.
- Avoid performing any privileged filesystem actions based solely on archive-provided names.
- Prefer running unpack operations under restricted user accounts with minimal access to system files, reducing the blast radius if a permission change occurs.
- Incorporate defense-in-depth measures such as filesystem sandboxing (e.g., containers, chroots, restricted workspaces) around tooling that processes untrusted archives.
How teams detect issues like this
Detecting this vulnerability and similar patterns typically involves reviewing both code and runtime behavior:
- Static analysis and code review:
- Search for code that performs
chmod,chown, or similar permission-altering calls using path strings derived from archive headers or other untrusted sources. - Flag patterns where path sanitization and permission changes are implemented in separate steps, especially if they use different path variables.
- Review extraction utilities and packaging scripts for missing checks that ensure all filesystem operations stay within a designated root.
- Policy-based checks in CI/CD:
- Enforce coding guidelines that require canonicalization of paths before any security-sensitive operation.
- Use automated linters or security-focused static analysis tools that can detect path traversal risks (CWE-22) and improper permission assignment (CWE-732).
- Runtime and system monitoring:
- Monitor for unexpected permission changes, especially on system directories or application configuration paths, using audit frameworks (e.g., auditd on Linux).
- Track invocations of packaging or extraction tools in build pipelines and correlate with anomalous chmod activity.
- Artifact and supply-chain controls:
- Scan wheel and archive contents for suspicious path patterns (e.g., absolute paths,
../segments, or references to system directories). - Maintain an allowlist of expected directory structures for internal packages and alert on deviations.

