security: enforce multifile download path boundary#9258
Conversation
JPPhoto
left a comment
There was a problem hiding this comment.
@Ersa-tech Thanks for your PR! I would like you to take a look at this issue, please:
-
invokeai/app/services/download/download_default.py:183andinvokeai/app/services/download/download_default.py:686multifile_download()now resolves each child part path before storing it on the childDownloadJob, but leaves the parentMultiFileDownloadJob.destunchanged. When a caller passes a relativedest, the child starts with an absolutedownload_path, then_mfd_started()tries to make that absolute path relative to the original relative parent path. That raisesValueError.A direct service call such as
multifile_download(parts=[RemoteModelFile(..., path=Path("sub/file.bin"))], dest=Path("relative-dest"))reaches this path. The PR changes the child path to(dest / part.path).resolve()atinvokeai/app/services/download/download_default.py:195and stores it inDownloadJob.destat line 200, while_mfd_started()still usesdownload_job.download_path.relative_to(mf_job.dest)at line 686. Since_execute_cb()catches and logs callback exceptions atinvokeai/app/services/download/download_default.py:775, the child download can complete while the parent job never gets itsdownload_pathand the caller's parenton_startcallback is skipped.I reproduced this against the PR worktree. The job completed, but the log showed
ValueError: '/tmp/relative-dest-pr9258/sub/file.bin' is not in the subpath of 'relative-dest-pr9258'.To expose this issue, add a test that calls
multifile_download()with a relativedest, waits for completion, and asserts the parentMultiFileDownloadJob.download_pathis populated and the parenton_startcallback ran.
Summary
assert-based multifile download path guard with an explicit runtimeValueError.Why
RemoteModelFile.pathis documented as relative to the model root. The multifile download service should enforce that boundary at runtime, including production/optimized Python runs whereassertstatements are disabled. Resolving both paths also catches..traversal that a lexical path check can miss.Testing
python -m compileall invokeai/app/services/download/download_default.py tests/app/services/download/test_download_queue.pyFocused pytest could not start in this local environment because project test imports require additional runtime dependencies not installed here; after installing
blake3andpicklescan, collection next failed on missingonnxruntime.