Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.48k stars 4.81k forks source link

Regression: AuthenticationFailed instead of InvalidOperationException when setting blob metadata with invalid keys #35377

Open pharring opened 1 year ago

pharring commented 1 year ago

Between Azure.Storage.Blobs 12.15.0 and 12.15.1 there was a regression of behavior around setting blob metadata with invalid (non CSharp identifiers)

Repro:

using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;

BlobServiceClient blobServiceClient = new("DefaultEndpointsProtocol=https;AccountName=REDACTED;AccountKey=REDACTED;EndpointSuffix=core.windows.net");
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient("test");
await blobContainerClient.CreateIfNotExistsAsync();

BlockBlobClient blockBlobClient = blobContainerClient.GetBlockBlobClient("blob");
if (!await blockBlobClient.ExistsAsync())
{
    await blockBlobClient.UploadAsync(Stream.Null, new BlobUploadOptions { });
}

await blockBlobClient.SetMetadataAsync(new Dictionary<string, string>
{
    ["Key£"] = "value"
});

In 12.15.0, this throws an InvalidOperationException with the message "Unable to add header to request or content". In 12.15.1, this throws a RequestFailedException with the status code of 403 and the message "Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature."

Looking a little closer, the regression can also be seen using 12.15.0 with Azure.Core 1.30.0

Note that neither exception is quite "on the mark". For example, if the key is "123" (not a valid C# identifier), you'll get a RequestFailedException with 400 (Bad Request) and an error code of InvalidMetadata. It would be nice to get that in all cases.

Note also that the Azurite emulator (at least the version I have installed with VS 2022) doesn't faithfully emulate this behavior. It allows metadata keys that contain punctuation such as '+'. But it will fail in the same way with characters outside the ASCII range.

github-actions[bot] commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

jsquire commented 1 year ago

//cc: @AlexanderSher

Alex - can you verify this isn't a regression in Core?

github-actions[bot] commented 1 year ago

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

navba-MSFT commented 1 year ago

Adding Service team to look into this.

@xgithubtriage Could you please look into this once you get a chance ? Thanks in advance.