Skip to content

[Storage] Fixed SAS generation for blob names with a backslash - #48883

Open
anjaliratnam-msft wants to merge 3 commits into
Azure:mainfrom
anjaliratnam-msft:sas-backslash-issue
Open

[Storage] Fixed SAS generation for blob names with a backslash#48883
anjaliratnam-msft wants to merge 3 commits into
Azure:mainfrom
anjaliratnam-msft:sas-backslash-issue

Conversation

@anjaliratnam-msft

Copy link
Copy Markdown
Member

A SAS generated for a blob/path/file name containing a backslash (\) is always rejected with 403 AuthenticationFailed. The service canonicalizes \ to / when it rebuilds the signed resource to validate the signature, but the SDK signs the name verbatim. The two strings differ, so the signatures never match. Backslashes are valid in flat blob names and in HNS paths, and the Files service treats \ as a path separator, so this is reachable in all three services. This resolves #48690.

Fix

Normalize \ to / when building the signed resource:

  • azure-storage-blob — normalize blob_name in generate_blob, before it is used for both the signed resource and the signed directory depth (sdd).
  • azure-storage-file-datalakegenerate_directory_sas computes sdd itself and passes it explicitly, overriding the blob value, so the depth is now computed from the canonicalized name.
  • azure-storage-file-share — normalize the assembled resource_path in generate_file.

Testing

Added one live test per package that creates a resource with a backslash in the name, generates a SAS for it, and reads through that SAS.

Copilot AI balanced review requested due to automatic review settings September 3, 2026 15:27
@github-actions github-actions Bot added the Storage Storage Service (Queues, Blobs, Files) label Sep 3, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation consistently matches service canonicalization and includes coverage across all affected Storage packages.

Pull request overview

Fixes SAS authentication for Storage resource names containing backslashes by matching service-side canonicalization.

Changes:

  • Normalizes backslashes in Blob and File Share SAS resource paths.
  • Corrects Data Lake signed-directory depth calculation.
  • Adds live regression tests and changelog entries.
File summaries
File Description
sdk/storage/azure-storage-file-share/tests/test_file.py Tests SAS access for backslash file paths.
sdk/storage/azure-storage-file-share/CHANGELOG.md Documents the fix.
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared_access_signature.py Canonicalizes file resource paths.
sdk/storage/azure-storage-file-datalake/tests/test_directory.py Tests directory SAS canonicalization and depth.
sdk/storage/azure-storage-file-datalake/CHANGELOG.md Documents the fix.
sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared_access_signature.py Calculates depth from the canonicalized path.
sdk/storage/azure-storage-blob/tests/test_common_blob.py Tests SAS access for backslash blob names.
sdk/storage/azure-storage-blob/CHANGELOG.md Documents the fix.
sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py Canonicalizes blob names before signing.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 3, 2026 16:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Data Lake SAS generation calculates an incorrect directory depth when a backslash canonicalizes to the root path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 4, 2026 00:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The canonicalization is consistently implemented across all affected services and covered by targeted live tests.

Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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

Labels

Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

2 participants