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 @@
## 2023-10-27 - Path traversal in skill zip extraction
**Vulnerability:** Path traversal vulnerability due to unchecked zip file extraction.
**Learning:** `zipfile.ZipFile.extractall()` is vulnerable to directory traversal attacks if the zip file contains relative paths like `../`.
**Prevention:** Always validate every path in the archive using `os.path.abspath` and `str.startswith` instead of `.resolve()` or `.is_relative_to()` before extracting to prevent path traversal while maintaining performance.
6 changes: 6 additions & 0 deletions helpers/skills_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def _unzip_to_temp_dir(zip_path: Path) -> Path:
target.mkdir(parents=True, exist_ok=True)

with zipfile.ZipFile(zip_path, "r") as z:
target_abs = os.path.abspath(str(target))
target_prefix = target_abs + ("" if target_abs.endswith(os.sep) else os.sep)
for member in z.namelist():
member_path = os.path.abspath(os.path.join(target_abs, member))
if not member_path.startswith(target_prefix):
raise ValueError(f"Unsafe path in archive: {member}")
z.extractall(target)

# If zip contains a single top-level folder, treat that as the root
Expand Down