CORS behavior mismatch between client and REST API

Chris Dailey 0 Reputation points
2023-12-14T14:52:05.04+00:00

I'm trying to list (and eventually download) blobs using a SAS token. This works fine with the REST API, but when I try to do the same thing with the JS/TS client, I get like 8 CORS errors, I guess from the preflight getting rejected. This is weird to me because I have CORS exceptions loaded and I can list blobs using the SAS token by hitting the REST API. I feel like I must be missing something; what am I not getting?

User's image

User's image

User's image

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
Microsoft 365 and Office | Development | Office JavaScript API
{count} votes

1 answer

Sort by: Most helpful
  1. Anand Prakash Yadav 7,865 Reputation points Microsoft External Staff
    2023-12-19T12:22:16.38+00:00

    Hello @Chris Dailey,

    Thanks for your query.

    If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at $somesite" indicating that the request was blocked due to violating the CORS security rules.
    Part of the error text is a "reason" message that provides added insight into what went wrong. The reason messages are listed below; click the message to open an article explaining the error in more detail and offering possible solutions.
    Reason: CORS request did not succeed: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSDidNotSucceed

    In many cases, it is caused by a browser plugin (e.g. an ad blocker or privacy protector) blocking the request.
    Other possible causes include:
    Trying to access an https resource that has an invalid certificate will cause this error.
    Trying to access an http resource from a page with an https origin will also cause this error.
    As of Firefox 68, https pages are not permitted to access http://localhost, although this may be changed by Bug 1488740.
    The server did not respond to the actual request (even if it responded to the Preflight request). One scenario might be an HTTP service being developed that panicked without returning any data.

    CORS errors: https://learn.microsoft.com/en-us/rest/api/storageservices/cross-origin-resource-sharing--cors--support-for-the-azure-storage-services


Your answer

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