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

Azure.Storage.Blobs doesn't work with SAS token with ? in front for net472 #44373

Open erdembayar opened 5 months ago

erdembayar commented 5 months ago

Library name and version

Azure.Storage.Blobs 12.20.0

Describe the bug

I have following C# project with net472 tfm. If I use SharedAccessSignature=?sv=2018-03-28&ss=b&srt=co&sp=rcw&se=2025-01-01T21:30:06Z&spr=https&sig=xxxxxxxx%3D instead of SharedAccessSignature=sv=2018-03-28&ss=b&srt=co&sp=rcw&se=2025-01-01T21:30:06Z&spr=https&sig=xxxxxxxx%3D then I get error. Same code works fine with net6.0 sdk with ? in front of SAS.

AccessBlobStorageByConnectionString.zip

Expected behavior

There should be no behavior difference between net472 and net6.0 for same package + Id.

Actual behavior

It doesn't work if ? in front of the SAS

Reproduction Steps

See my C# project and use your own blob storage settings AccessBlobStorageByConnectionString.zip

Environment

Version 17.11.0 Preview 1.1 , sdk 8.0.400-preview.0.24276.1

github-actions[bot] commented 5 months ago

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

agr commented 5 months ago

I tried some various storage API calls with and only blob download seems to fail when ? is present in SharedAccessSignature. Code I used:

using System;
using System.Threading.Tasks;
using Azure;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;

class Program
{
    static async Task Main(string[] args)
    {
        const string connectionString = "BlobEndpoint=https://<my storage account>.blob.core.windows.net/;SharedAccessSignature=?ss=b&sv=2022-11-02&srt=sco&sp=rl&se=2024-06-04T09:09:36Z&st=2024-06-04T01:09:36Z&spr=https&sig=<signature>";

        // Create the BlobServiceClient using the connection string
        BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

        try
        {
            await foreach (BlobContainerItem client in blobServiceClient.GetBlobContainersAsync())
            {
                Console.WriteLine($"Container name: {client.Name}");
            }

            var containerClient = blobServiceClient.GetBlobContainerClient("container");

            await foreach (BlobItem blob in containerClient.GetBlobsAsync())
            {
                Console.WriteLine($"Blob name: {blob.Name}");
            }

            var blobClient = containerClient.GetBlobClient("blob.json");
            var content = await blobClient.DownloadContentAsync(); // only this line fails
            Console.WriteLine("done");
        }
        catch (RequestFailedException ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
            Console.WriteLine($"ErrorCode: {ex.ErrorCode}");
            Console.WriteLine($"Status: {ex.Status}");
        }
    }
}
erdembayar commented 5 months ago

When this issue would be triaged @JoshLove-msft @jsquire?

jsquire commented 5 months ago

@erdembayar: This issue has been triaged and assigned to the Azure Storage team who own the package. We do not have insight into their process or when they may address this.