Skip to content

Commit 7a7d2de

Browse files
authored
Fixed security issue around wheel unpack (#675)
A maliciously crafted wheel could cause the permissions of a file outside the unpack tree to be altered. Fixes CVE-2026-24049.
1 parent 41418fa commit 7a7d2de

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/news.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Release Notes
77
v70.1
88
- Importing ``wheel.bdist_wheel`` now emits a ``FutureWarning`` instead of a
99
``DeprecationWarning``
10+
- Fixed ``wheel unpack`` potentially altering the permissions of files outside of the
11+
destination tree with maliciously crafted wheels (CVE-2026-24049)
1012

1113
**0.46.1 (2025-04-08)**
1214

src/wheel/_commands/unpack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def unpack(path: str, dest: str = ".") -> None:
1919
destination = Path(dest) / namever
2020
print(f"Unpacking to: {destination}...", end="", flush=True)
2121
for zinfo in wf.filelist:
22-
wf.extract(zinfo, destination)
22+
target_path = Path(wf.extract(zinfo, destination))
2323

2424
# Set permissions to the same values as they were set in the archive
2525
# We have to do this manually due to
2626
# https://github.com/python/cpython/issues/59999
2727
permissions = zinfo.external_attr >> 16 & 0o777
28-
destination.joinpath(zinfo.filename).chmod(permissions)
28+
target_path.chmod(permissions)
2929

3030
print("OK")

tests/commands/test_unpack.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,26 @@ def test_unpack_executable_bit(tmp_path: Path) -> None:
5454
run_command("unpack", "--dest", tmp_path, wheel_path)
5555
assert not script_path.is_dir()
5656
assert stat.S_IMODE(script_path.stat().st_mode) == 0o755
57+
58+
59+
@pytest.mark.skipif(
60+
platform.system() == "Windows", reason="Windows does not support chmod()"
61+
)
62+
def test_chmod_outside_unpack_tree(tmp_path_factory: TempPathFactory) -> None:
63+
wheel_path = tmp_path_factory.mktemp("build") / "test-1.0-py3-none-any.whl"
64+
with WheelFile(wheel_path, "w") as wf:
65+
wf.writestr(
66+
"test-1.0.dist-info/METADATA",
67+
"Metadata-Version: 2.4\nName: test\nVersion: 1.0\n",
68+
)
69+
wf.writestr("../../system-file", b"malicious data")
70+
71+
extract_root_path = tmp_path_factory.mktemp("extract")
72+
system_file = extract_root_path / "system-file"
73+
extract_path = extract_root_path / "subdir"
74+
system_file.write_bytes(b"important data")
75+
system_file.chmod(0o755)
76+
run_command("unpack", "--dest", extract_path, wheel_path)
77+
78+
assert system_file.read_bytes() == b"important data"
79+
assert stat.S_IMODE(system_file.stat().st_mode) == 0o755

0 commit comments

Comments
 (0)