Skip to content
Merged
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
13 changes: 12 additions & 1 deletion invokeai/app/services/bulk_download/bulk_download_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,15 @@ def get_path(self, bulk_download_item_name: str) -> str:
def _is_valid_path(self, path: Union[str, Path]) -> bool:
"""Validates the path given for a bulk download."""
path = path if isinstance(path, Path) else Path(path)
return path.exists()

# Resolve the path to handle any path traversal attempts (e.g., ../)
resolved_path = path.resolve()

# The path may not traverse out of the bulk downloads folder or its subfolders
does_not_traverse = resolved_path.parent == self._bulk_downloads_folder.resolve()

# The path must exist and be a .zip file
does_exist = resolved_path.exists()
is_zip_file = resolved_path.suffix == ".zip"

return does_exist and is_zip_file and does_not_traverse