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

Broken StoragePath.Normalize, leading to broken Azure SAS URLs when using Azurite #94

Open
vvuk opened this issue Dec 20, 2024 · 0 comments

Comments

@vvuk
Copy link

vvuk commented Dec 20, 2024

Azure SAS URLs are created here in AzureBlobStorage using:

			if (includeUrl) {
				string url = new Uri(_client.Uri, StoragePath.Normalize(fullPath)).ToString();
				url += "?";
				url += sas;
				return url;
			}

Typically, the _client.Uri will be something like https://myaccount.blob.core.windows.net/ or similar. However, when using Azurite, it's something like http://127.0.0.1:51256/devstoreaccount1/, with the devstoreaccount1 part being important.

In the function above, the fullPath should be something like container/name. However, StoragePath.Normalize is returning /container/name, and I don't understand why. This code here is doing it, removeTrailingSlash is false here:

			return removeTrailingSlash
			   ? path
			   : PathSeparatorString + path;

This makes no sense -- if "remove trailing slash" is false, the method.. prepends a slash? Also, given how this method is implemented, it's impossible for there to ever be a leading or trailing slash here. It splits the path by the separator with RemoveEmptyEntries and then recombines it.

All of this leads to the Uri() constructor stripping devstoreaccount1 from the base Uri. There's an additional subtle bug here -- connection strings for Azurite include a BlobEndpoint=http://127.0.0.1:51256/devstoreaccount1 (note lack of trailing slash). This works until a Uri constructor is used like the above -- Uri will strip off the last base path element if it doesn't end in a /.

@vvuk vvuk changed the title Broken StoragePath.Normalize, leading to broken Azure SAS URLs when using Azurite -- Broken StoragePath.Normalize, leading to broken Azure SAS URLs when using Azurite Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant