question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blob SAS fails if query string contains URL-encoded value

See original GitHub issue

Which service(blob, file, queue, table) does this issue concern?

blob (but may be applied to queue too)

Which version of the Azurite was used?

v3.5.0

Where do you get Azurite? (npm, DockerHub, NuGet, Visual Studio Code Extension)

DockerHub

What’s the Node.js version?

v10.19.0

What problem was encountered?

SAS authentification for blob fails if SAS contains URL-encoded strings (e.g. URL-encoded filename in Content-Disposition)

Steps to reproduce the issue?

I used python client for a minimal reproducible code,

import datetime
import urllib.parse

import requests
from azure.storage.blob.blockblobservice import BlockBlobService
from azure.storage.blob.models import BlobPermissions, ContentSettings

azure_blob_service = BlockBlobService(...)

name = 'te st.txt'
name_quoted = urllib.parse.quote(name)  # will result 'te%20st.txt'

# assume that the file is already uploaded in the blob storage

sas_token = azure_blob_service.generate_blob_shared_access_signature(
    'test',
    name,
    permission=BlobPermissions(read=True),
    content_disposition=f'inline; filename="{name_quoted}"',
    expiry=datetime.datetime(2030, 1, 1)
)

url = azure_blob_service.make_blob_url(
    'test',
    name_quoted,
    sas_token=sas_token
)

print(requests.get(url))
# In real Azure Blob Storage, this results 200 OK response,
# In Azurite, this results 403 Forbidden response.

Have you found a mitigation/solution?

I guess that in BlobSASAuthenticator.ts, query values (which are fetched from req.getQuery(...)) are already decoded by express and qs packages but this.decodeIfExist(...) function applies decodeURIComponent one more time, which results in different SAS signature values.

For example, contentDisposition value from rscd query key,

  • expected : inline; filename="te%20st.txt"
  • actual : inline; filename="te st.txt"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iBavtovichcommented, Sep 20, 2020

@pjknkda @XiaoningLiu Probably, the problem is caused by the blobName and not by contentDisposition, which is obtained from incoming request as url-encoded value. But signature in Java SDK (I expect in others as well) is calculated from un-url-encoded value. As a result in case if your blob name has some symbols which should be encoded (in my case it it /), there going to be sas signature mismatch in Azurite. Seems like the fix is simple and trivail: just get decoded value for the blob name.

0reactions
pjknkdacommented, Feb 5, 2022

This seems to have been fixed by #1104 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL encoding give auth error when using azure blob rest api
When I put a %20 instead of a space in key I get 403 Server failed to authenticate the request. Make sure the...
Read more >
Blob SAS URI character decoded when passed as Query ...
I wanted to pass the SAS URI of a image file to Azure Functions as query parameters. the value of Authorization header is...
Read more >
azure blob storage get file url - El Primer Grande
One SftpCreate for an initial empty blob created when opening the file and one ... The value should be URL-encoded as it would...
Read more >
How to query private blob storage with SQL and Azure Synapse
Each SAS parameter is a pair of 'key=value' data in the querystring; The querystring is already URL encoded, so you can include it...
Read more >
Class BlockBlobClient | Azure SDK for .NET
When using base-64 encoding, the pre-encoded string must be 64 bytes or less. Block ID values can be duplicated in different blobs. A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found