Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/simantic/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ def _unpack_zip(payload: bytes, target: Path) -> None:
for name in archive.namelist():
# Refuse anything that would land outside the target.
dest = (incoming / name).resolve()
if not str(dest).startswith(str(incoming.resolve())):
# A path check, not a string prefix: `.x.incoming-evil` shares the prefix.
if not dest.is_relative_to(incoming.resolve()):
raise InstallError(f"archive has an unsafe path: {name}")
archive.extractall(incoming)
if target.exists():
Expand Down
8 changes: 8 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,11 @@ def test_pyrite_manifest_resolves_sim_and_rust_engine(home, monkeypatch):
assert install.resolve("sim").path == "pyrite/1.2.3/sim-osx-arm64"
monkeypatch.setattr(install, "download", lambda a, timeout=300: engine_zip({"simantic_rust.abi3.so": b"x"}))
assert install.install_rust_engine() == install.rust_engine_root() / "1.2.3"


def test_unpack_zip_refuses_a_sibling_sharing_the_prefix(tmp_path):
buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as z:
z.writestr("../.engine.incoming-evil/f", b"x")
with pytest.raises(install.InstallError, match="unsafe path"):
install._unpack_zip(buf.getvalue(), tmp_path / "engine")
Loading