[azure-ai-ml] Fix path traversal vulnerability in storage download helpers#46693
Open
ayushhgarg-work wants to merge 3 commits intoAzure:mainfrom
Open
[azure-ai-ml] Fix path traversal vulnerability in storage download helpers#46693ayushhgarg-work wants to merge 3 commits intoAzure:mainfrom
ayushhgarg-work wants to merge 3 commits intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
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.py—BlobStorageClient.download()azure/ai/ml/_artifacts/_gen2_storage_helper.py—Gen2StorageClient.download()azure/ai/ml/_artifacts/_fileshare_storage_helper.py—recursive_download()Details
The
downloadmethods construct local file paths from server-returned blob/file names without verifying the resolved path stays under the destination. A name like../../etc/maliciouswould 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.