Skip to content

Commit efcd159

Browse files
fix(app): path traversal via bulk downloads paths
1 parent 997e619 commit efcd159

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

invokeai/app/services/bulk_download/bulk_download_default.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,15 @@ def get_path(self, bulk_download_item_name: str) -> str:
150150
def _is_valid_path(self, path: Union[str, Path]) -> bool:
151151
"""Validates the path given for a bulk download."""
152152
path = path if isinstance(path, Path) else Path(path)
153-
return path.exists()
153+
154+
# Resolve the path to handle any path traversal attempts (e.g., ../)
155+
resolved_path = path.resolve()
156+
157+
# The path may not traverse out of the bulk downloads folder or its subfolders
158+
does_not_traverse = resolved_path.parent == self._bulk_downloads_folder.resolve()
159+
160+
# The path must exist and be a .zip file
161+
does_exist = resolved_path.exists()
162+
is_zip_file = resolved_path.suffix == ".zip"
163+
164+
return does_exist and is_zip_file and does_not_traverse

0 commit comments

Comments
 (0)