Skip to content
Open
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
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2025-05-23 - Prevent Zip Slip Vulnerability
**Vulnerability:** `zipfile.ZipFile.extractall()` is vulnerable to path traversal if the archive contains malicious paths with `../`.
**Learning:** Never blindly extract archives using `extractall()`.
**Prevention:** Iterate over `z.namelist()`, resolve the extraction path, and explicitly verify it falls inside the intended destination using `Path.is_relative_to()` before extracting.
6 changes: 5 additions & 1 deletion helpers/skills_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def _unzip_to_temp_dir(zip_path: Path) -> Path:
target.mkdir(parents=True, exist_ok=True)

with zipfile.ZipFile(zip_path, "r") as z:
z.extractall(target)
for member in z.namelist():
member_path = (target / member).resolve()
if not member_path.is_relative_to(target.resolve()):
raise ValueError(f"Zip slip vulnerability detected: {member}")
z.extract(member, target)

# If zip contains a single top-level folder, treat that as the root
children = [p for p in target.iterdir()]
Expand Down