Blob file is accessible from Cache without SAS token [using Azure Front Door and CDN Profile]

Sachin K 0 Reputation points
2024-01-19T12:18:56.8866667+00:00

Hi,

I am using Azure Blob storage to store the file. To fetch the file I generate a URL with SAS token. Also, I am using the Azure Front Door and CDN Profile to cache the file. The file is accessible with the URL with SAS token. If I call the URL again it will get cached (I got X-Cache : TCP_HIT in the response header).

Problem
After caching the file, If I call the same URL without SAS token the file is accessible.

Question
How can I restrict the access of files from the cache without using the SAS token?

Below I have shared the caching settings in Azure Front Door and CDN Profile
Capture

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,920 questions
Azure Content Delivery Network
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GitaraniSharma-MSFT 49,586 Reputation points Microsoft Employee
    2024-01-19T13:22:08.14+00:00

    Hello @Sachin K ,

    Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.

    I understand that your Azure Storage Blob file setup with Azure CDN is accessible from Cache without SAS token, and you would like to restrict the access of files from the cache. We have a document for using Azure CDN with SAS, which you can refer in this case:

    https://learn.microsoft.com/en-us/azure/cdn/cdn-sas-storage-support

    There are two options recommended for using SAS with Azure CDN:

    Option 1: Using SAS with pass-through to blob storage from Azure CDN

    Fine-tune the cache duration either by using caching rules or by adding Cache-Control headers at the origin server. Because Azure CDN treats the SAS token as a plain query string, as a best practice you should set up a caching duration that expires at or before the SAS expiration time. Otherwise, if a file is cached for a longer duration than the SAS is active, the file may be accessible from the Azure CDN origin server after the SAS expiration time has elapsed. If this situation occurs, and you want to make your cached file inaccessible, you must perform a purge operation on the file to clear it from the cache.

    Option 2: Using CDN security token authentication with a rewrite rule:

    To use Azure CDN security token authentication, you must have an Azure CDN Premium from Edgio profile. This option is the most secure and customizable.

    I believe you are using option 1, so as suggested, you should set up a caching duration that expires at or before the SAS expiration time.

    • Select your Azure CDN endpoint, select Caching rules, then select Cache every unique URL from the Query string caching list.

    User's image

    • And then go to the Rules engine of the Azure CDN endpoint and add the Global rule to set/override the cache expiration settings.

    User's image

    You should set the cache behavior to Override and set up a caching duration that expires at or before the SAS expiration time.

    Override: Ignore origin-provided cache duration; use the provided cache duration instead. This setting doesn't override cache-control: no-cache.

    Refer: https://learn.microsoft.com/en-us/azure/cdn/cdn-how-caching-works#default-caching-behavior

    https://learn.microsoft.com/en-us/azure/cdn/cdn-caching-rules#caching-behavior-settings

    Kindly let us know if the above helps or you need further assistance on this issue.


    Please don’t forget to "Accept the answer" wherever the information provided helps you, this can be beneficial to other community members.


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.