FIX: sanitize metadata file name in azure_blob_storage_target#2193
Merged
Conversation
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.
Description
AzureBlobStorageTargetlets a prompt override the blob name viaprompt_metadata["file_name"], and that value was concatenated unsanitized into the blob path. A value like../../team-b/results.txtis canonicalized by Azure to escape the configured container prefix, allowing a write/overwrite outside the intended location. This validatesfile_nameat the boundary and rejects anything that isn't a bare leaf name.This is defense-in-depth, not a live exploit in PyRIT's current trust model: whoever sets
file_namealready holds the container credential, so no privilege boundary is crossed today. It matters for a shared multi-tenant deployment that relies on prefix-based isolation between teams; the fix hardens that boundary before it is depended upon.Changes
pyrit/prompt_target/azure_blob_storage_target.py_sanitize_file_name()— rejects path separators and traversal (file_name != posixpath.basename(file_name), plus./..and backslash checks) with aValueError.prompt_metadata["file_name"]is read, so a bad name fails before any upload (write primitive is blocked at the source, not at each consumer of the resulting URL).Tests
tests/unit/prompt_target/target/test_prompt_target_azure_blob_storage.py../../admin/stolen.txt,sub/dir/file.txt,..,.,dir\file.txt,/abs.txt).file_nameraises and_upload_blob_asyncis never called.