Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Azure Storage BlobClient doesn't properly escape filenames with certain characters #11602

Closed
kganjam opened this issue Apr 26, 2020 · 2 comments · Fixed by #11657
Closed
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@kganjam
Copy link

kganjam commented Apr 26, 2020

Describe the bug
BlobClient doesn't properly escape filenames with certain characters such as '#'. This results in a time-consuming-to-debug exception.

Expected behavior
BlobClient constructor should automatically handle proper escaping of filenames. It took me a while to figure out a workaround. Simple Uri.EscapeUriString is insufficient, though Uri.EscapeDataString appears to work.

If this behavior is by design, then the constructor should at least throw an exception up front to warn users of invalid characters and/or the docs should be updated to explicitly state how the filename needs to be encoded.

Actual behavior (include Exception or Stack Trace)
Azure.RequestFailedException: 'Service request failed.
Status: 404 (The specified blob does not exist.)
ErrorCode: BlobNotFound

To Reproduce

// These two blobs already exists and are visible in Storage Explorer
string myDir = @"MyDir_20200410/MyDir2";
string fileNameWithSpaces = "My File Name.pdf"; 
string fileNameWithSpacesAndPound = "My File Name#.pdf"; 

var blob = new BlobClient(@"DefaultEndpointsProtocol=https;AccountName=<redacted>;AccountKey=<redacted>;EndpointSuffix=core.windows.net", "MyContainer", $"{myDir}/{fileNameWithSpaces});
 var p = blob.GetProperties(); // Works with unescaped spaces

// A workaround to escape the filename
var b = new RequestUriBuilder();
b.AppendPath(Path.GetFileName(fileNameWithSpacesAndPound));
var escapedFileName = b.Path;  

blob = new BlobClient(@"DefaultEndpointsProtocol=https;AccountName=<redacted>;AccountKey=<redacted>;EndpointSuffix=core.windows.net", "MyContainer", $"{myDir}/{escapedFileName}");
 var p = blob.GetProperties(); // Works with escaped name 

blob = new BlobClient(@"DefaultEndpointsProtocol=https;AccountName=<redacted>;AccountKey=<redacted>;EndpointSuffix=core.windows.net", "MyContainer", $"{myDir}/{fileNameWithSpacesAndPound});
 var p = blob.GetProperties(); // Throws with unescaped pound character

Environment:

  • Name and version of the Library package used: Azure.Storage.Blobs 12.4.1
  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects):
    .NET Core SDK (reflecting any global.json):
    Version: 3.1.201
    Commit: b1768b4ae7

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.201\

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

.NET Core SDKs installed:
1.1.14 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.512 [C:\Program Files\dotnet\sdk]
2.1.801 [C:\Program Files\dotnet\sdk]
2.2.401 [C:\Program Files\dotnet\sdk]
3.1.201 [C:\Program Files\dotnet\sdk]

  • IDE and version : [e.g. Visual Studio 16.3]
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 26, 2020
@jsquire jsquire changed the title [BUG] [BUG] Azure Storage BlobClient doesn't properly escape filenames with certain characters Apr 26, 2020
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Apr 26, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Apr 26, 2020
@ghost
Copy link

ghost commented Apr 26, 2020

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@seanmcc-msft
Copy link
Member

seanmcc-msft commented Apr 29, 2020

I've put out a PR to resolve this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
3 participants