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.
- And then go to the Rules engine of the Azure CDN endpoint and add the Global rule to set/override the cache expiration settings.
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.