Skip to content

[azure-ai-ml] Fix path traversal vulnerability in storage download helpers#46693

Open
ayushhgarg-work wants to merge 3 commits intoAzure:mainfrom
ayushhgarg-work:ayushhgarg/blobclient
Open

[azure-ai-ml] Fix path traversal vulnerability in storage download helpers#46693
ayushhgarg-work wants to merge 3 commits intoAzure:mainfrom
ayushhgarg-work:ayushhgarg/blobclient

Conversation

@ayushhgarg-work
Copy link
Copy Markdown
Member

@ayushhgarg-work ayushhgarg-work commented May 4, 2026

Summary

Fixes a path traversal vulnerability (CWE-22) in the download methods of all three storage helpers that could allow server-supplied blob/file names containing .. segments to write files outside the intended destination directory.

Changes

Added path validation in the download flows to ensure resolved target paths remain within the caller-specified destination directory. Malicious paths are skipped with a warning log.

Affected files:

  • azure/ai/ml/_artifacts/_blob_storage_helper.pyBlobStorageClient.download()
  • azure/ai/ml/_artifacts/_gen2_storage_helper.pyGen2StorageClient.download()
  • azure/ai/ml/_artifacts/_fileshare_storage_helper.pyrecursive_download()

Details

The download methods construct local file paths from server-returned blob/file names without verifying the resolved path stays under the destination. A name like ../../etc/malicious would escape the download directory.

The fix resolves both the destination and target to absolute paths, then uses Path.relative_to() to confirm the target is a descendant of the destination. Items that fail this check are skipped and a warning is logged.

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

This PR addresses a CWE-22 path traversal risk in the artifact storage download helpers by validating that server-supplied blob/file paths resolve under the caller-provided destination directory before writing to disk.

Changes:

  • Add resolved-path containment checks (via Path.resolve() + Path.relative_to()) to block .. traversal and other escaping paths during downloads.
  • Skip suspicious items and emit a warning log instead of writing outside the destination directory.
  • Apply the same protection pattern across Blob, ADLS Gen2, and Fileshare download implementations.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_blob_storage_helper.py Adds destination/target resolution and containment checks before writing downloaded blobs.
sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_gen2_storage_helper.py Adds equivalent containment validation for ADLS Gen2 get_paths() results prior to directory creation or file writes.
sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_fileshare_storage_helper.py Adds containment validation for both file and subdirectory downloads in the recursive fileshare helper.

Comment thread sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_blob_storage_helper.py
Comment thread sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_blob_storage_helper.py
Comment thread sdk/ml/azure-ai-ml/azure/ai/ml/_artifacts/_fileshare_storage_helper.py Outdated
ayushhgarg-work and others added 2 commits May 4, 2026 14:27
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants