Unable to replicate the SasSignature SHA256 in Azure Blob diagnostic audit logs for DelegationSas tokenHash

Richard Hauer 1 Reputation point
2025-03-19T11:42:37.03+00:00

I have a solution that dynamically creates SAS tokens for a storage container by API. The API (Azure Fn) uses a Managed Identity to access the storage account. Thus, we use the "DelegationSas" authentication to generate the SAS token and return that to the user, who then uses the token to access the storage account.

This all works fine.

We have diagnostic audit logs on the storage account, connected to Event Grid so that we can record user activity. The events that are recorded include some Json specifying the tokenHash data for the identity used to access the Storage resource.

The relevant part looks like this:

{
    ... 
    "identity": {
        ...
        "tokenHash": "user-delegation([64-hex-chars]),SasSignature([64-hex-chars])",
        ...
    },
    ...
}

Now, according to the information in MS Docs here, the SasSignature value should be an "SHA 256 hash of the SAS token", but I am unable to replicate this value given the original SasToken generated for the user. I have captured this token verbatim for experimentation purposes and have tried many permutations to try and match this audit value, including:

  • Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( "sasToken incl sig" ) ) )
  • Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( "?sasToken incl sig" ) ) )
  • Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( "complete uri incl sasToken" ) ) )
  • Convert.ToHexString( SHA256.HashData( Encoding.UTF8.GetBytes( HttpUtility.UrlDecode( "sasToken incl sig" ) ) ) )
  • Convert.ToHexString( SHA256.HashData( Convert.FromBase64String( HttpUtility.UrlDecode( "sasToken just the sig" ) ) ) )

None of these are a match.

Does anyone have any information on how the value in the audit log is actually generated?

Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,537 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Richard Hauer 1 Reputation point
    2025-03-19T12:18:11.8766667+00:00

    After MANY additional permutations, I did actually find the answer!

    Convert.ToHexString( 
      SHA256.HashData( 
        Encoding.UTF8.GetBytes( 
          "[url-decoded SasToken sig parameter]"
        )
      )
    )
    

    The trick is we're hashing the Base64 String version of the SasToken's sig(nature) parameter, not turning the sig back into a byte[] and hashing that.

    I thought it was odd that Azure is hashing an HMAC (which is already a hash) but that's fine, as long as I can match the SAS back to the original user for audit purposes.

    0 comments No comments

  2. Hari Babu Vattepally 3,345 Reputation points Microsoft External Staff Moderator
    2025-03-19T14:13:46.0833333+00:00

    Hi @Richard Hauer,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this.

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept" the answer. Accepted answers show up at the top, resulting in improved discoverability for others.

    Issue: Unable to replicate the SasSignature SHA256 in Azure Blob diagnostic audit logs for DelegationSas tokenHash

    Solution: As you mentioned above that the key point is that you're hashing the Base64 String version of the SasToken's sig(nature) parameter, rather than converting the signature back into a byte[] and hashing that and you found it unusual that Azure is hashing an HMAC (which is already a hash), but it's acceptable as long as you can trace the SAS back to the original user for audit purposes.

    Convert.ToHexString( 
      SHA256.HashData( 
        Encoding.UTF8.GetBytes( 
          "[url-decoded SasToken sig parameter]"
        )
      )
    )
    

    If your issue remains unresolved or have further questions, please let us know in the comments how we can assist. We are here to help you and strive to make your experience better and greatly value your feedback.

    Please let us know if you have any further queries. I’m happy to assist you further. 


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.