Skip to content

SharedKeySigner generates invalid signatures when the name of the Blob container starts with the same name as Storage Account #22

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

Closed
private-yusuke opened this issue Apr 7, 2025 · 1 comment

Comments

@private-yusuke
Copy link

private-yusuke commented Apr 7, 2025

Thank you for maintaining this wonderful gem!

I tried using the gem today and came across a bug. Let me explain how it happened.

Let's say we have a variable like this:
c = AzureBlob::Client(account_name: foo, container: foo + bar, access_key: ...)
where foo and bar represent two values of String.

When we try to generate a signed URL using
c.signed_uri("path/to/blob", permissions: "rw", expiry: Time.at(Time.now.to_i + 300).utc.iso8601),
the resulting signature is invalid. This is because the canonicalizedResource computed from uri is incorrect since its prefix is being unnecessarily removed in the following lines:

if remove_prefix
uri = uri.clone
uri.path = uri.path.delete_prefix("/#{account_name}")
end

For example, if the original uri was "https://foo.blob.core.windows.net/foo-bar/baz" where its path would be "/foo-bar/baz", the uri.path will going to be changed to "-bar/baz", which would cause an error like this: bad component(expected absolute path component): -bar/baz (URI::InvalidComponentError).

It looks like this prefix trimming was helpful for users working with Azurite, but it causes issues when the name of the Blob container starts with the same name as the storage account.
As a user who does not use Azurite, I confirmed that when those lines of code are commented out, the signed URL feature works properly.

I have never used Azurite, and I could not immediately think of a way to fix this bug while making it compatible with Azurite. I am sorry that I could not write a possible solution here, but I thought it would be better to have an issue created than nothing.

@private-yusuke private-yusuke changed the title SharedKeySigner generates invalid signatures when Blob container shares the same name as Storage Account SharedKeySigner generates invalid signatures when Blob container starts with the same name as Storage Account Apr 7, 2025
@private-yusuke private-yusuke changed the title SharedKeySigner generates invalid signatures when Blob container starts with the same name as Storage Account SharedKeySigner generates invalid signatures when the name of the Blob container starts with the same name as Storage Account Apr 7, 2025
@JoeDupuis JoeDupuis reopened this Apr 23, 2025
@JoeDupuis
Copy link
Member

Thank you for reporting!
Fixed in 0.5.7.1

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

2 participants