Skip to content

contain artifact download paths to the destination directory#47378

Open
alhudz wants to merge 1 commit into
Azure:mainfrom
alhudz:storage-download-traversal
Open

contain artifact download paths to the destination directory#47378
alhudz wants to merge 1 commit into
Azure:mainfrom
alhudz:storage-download-traversal

Conversation

@alhudz
Copy link
Copy Markdown

@alhudz alhudz commented Jun 6, 2026

BlobStorageClient.download, Gen2StorageClient.download and recursive_download take the blob/file/directory name straight from the storage listing and join it onto the local destination. A stored item whose name carries .. segments resolves outside destination, 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 is myasset/../escaped.txt (prefix myasset/) lands escaped.txt in the parent of the download directory; expected the download to refuse it, actual it writes outside destination.

Resolve each target and require it to stay under the resolved destination before 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 trusted destination can't be worked around by a crafted remote name. Regression tests added under tests/internal_utils/unittests.

Copilot AI review requested due to automatic review settings June 6, 2026 06:17
@github-actions github-actions Bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Machine Learning labels Jun 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

Thank you for your contribution @alhudz! We will review the pull request and get back to you soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}"
)
@alhudz
Copy link
Copy Markdown
Author

alhudz commented Jun 6, 2026

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Machine Learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants