contain artifact download paths to the destination directory#47378
Open
alhudz wants to merge 1 commit into
Open
contain artifact download paths to the destination directory#47378alhudz wants to merge 1 commit into
alhudz wants to merge 1 commit into
Conversation
Contributor
|
Thank you for your contribution @alhudz! We will review the pull request and get back to you soon. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds path traversal protections to artifact download helpers (Blob, Gen2, File Share) and introduces unit tests to ensure server-controlled names containing .. cannot escape the intended local destination.
Changes:
- Add path traversal checks in Blob, Gen2, and File Share download paths by resolving local target paths and enforcing containment.
- Add unit tests covering traversal attempts for blob, gen2, and fileshare downloads.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_storage_download_traversal.py | New unit tests asserting traversal payloads are rejected and don’t write outside destination. |
| sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_blob_storage_helper.py | Adds destination/target resolution and containment check before writing downloaded blobs. |
| sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_gen2_storage_helper.py | Adds destination/target resolution and containment check before writing downloaded files. |
| sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_fileshare_storage_helper.py | Adds destination/target resolution and containment check for files and subdirectories in recursive download. |
Comment on lines
+249
to
+255
| resolved_destination = Path(destination).resolve() | ||
| for item in my_list: | ||
| blob_name = item.name[len(starts_with) :].lstrip("/") or Path(starts_with).name | ||
| target_path = Path(destination, blob_name).resolve() | ||
| if target_path != resolved_destination and not str(target_path).startswith( | ||
| str(resolved_destination) + os.sep | ||
| ): |
| file_data.write(file_content.readall()) | ||
|
|
||
| for f in folders: | ||
| sub_destination = Path(destination, f["name"]).resolve() |
Comment on lines
430
to
432
| sub_client = client.get_subdirectory_client(f["name"]) | ||
| destination = "/".join((destination, f["name"])) | ||
| recursive_download(sub_client, destination=destination, max_concurrency=max_concurrency) |
Comment on lines
+209
to
+218
| resolved_destination = Path(destination).resolve() | ||
| for item in mylist: | ||
| file_name = item.name[len(starts_with) :].lstrip("/") or Path(starts_with).name | ||
| target_path = Path(destination, file_name) | ||
| target_path = Path(destination, file_name).resolve() | ||
| if target_path != resolved_destination and not str(target_path).startswith( | ||
| str(resolved_destination) + os.sep | ||
| ): | ||
| raise ValueError( | ||
| f"Path name contains a path traversal entry and cannot be downloaded safely: {item.name}" | ||
| ) |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BlobStorageClient.download,Gen2StorageClient.downloadandrecursive_downloadtake the blob/file/directory name straight from the storage listing and join it onto the localdestination. A stored item whose name carries..segments resolves outsidedestination, so pulling an artifact from an attacker-influenced container or fileshare writes files anywhere the process can reach. Repro: a one-entry container whose blob name ismyasset/../escaped.txt(prefixmyasset/) landsescaped.txtin the parent of the download directory; expected the download to refuse it, actual it writes outsidedestination.Resolve each target and require it to stay under the resolved
destinationbefore writing, matching the zip/tar containment checks already in_local_job_invoker.py. The write site is the only layer that sees the final on-disk path, so a caller passing a trusteddestinationcan't be worked around by a crafted remote name. Regression tests added undertests/internal_utils/unittests.