[BUG] Error when CORS is set with multiple methods in the storage account
See original GitHub issueThis is a duplicate of https://github.com/Azure/azure-storage-net/issues/916. Decided to open a new issue since that repo was abandoned
Describe the bug
The storage sdk cannot handle a CORS policy with a rule that has multiple methods. To make this work we would need to create one rule for each method that we want CORS to be enabled
Expected behavior SDK should allow a CORS policy with a rule of comma delimited methods. ie. Access-Control-Allow-Methods: POST, GET, OPTIONS
Actual behavior (include Exception or Stack Trace) When setting up a function app with a blob trigger, the function host return the following error
Microsoft.WindowsAzure.Storage.StorageException : Requested value 'DELETE,GET,POST,PUT,MERGE,HEAD,OPTIONS,PATCH' was not found. ---> System.ArgumentException : Requested value 'DELETE,GET,POST,PUT,MERGE,HEAD,OPTIONS,PATCH' was not found.
at System.Enum.TryParseEnum(Type enumType,String value,Boolean ignoreCase,EnumResult& parseResult)
at System.Enum.Parse(Type enumType,String value,Boolean ignoreCase)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties.<>c.<ReadCorsPropertiesFromXml>b__67_0(XElement rule)
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
To Reproduce
- Create a storage account and set the following CORS policy
- Create a function app with a blob trigger pointing to this storage account
- Function will never trigger because of the storage sdk error. Should be able to find function host error under kudu
Environment:
- Windows Function App
- Node 10.14.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:18 (10 by maintainers)
Top Results From Across the Web
Azure Storage Blob CORS errors
The issue you are running into is because the browser had cached the CORS settings. Two things we discovered:
Read more >How to troubleshoot CORS error in Azure API Management ...
Preflight: "preflighted" requests the browser first sends an HTTP request using the OPTIONS method to the resource on the other origin, in order ......
Read more >Cross-Origin Resource Sharing (CORS) support for Azure ...
CORS is an HTTP feature that enables a web application running under one domain to access resources in another domain. You can set...
Read more >3 Ways to Fix the CORS Error — and How the Access- ...
If the frontend domain does not match the value, the browser raises the red flag and blocks the API request with the CORS...
Read more >CORS errors - HTTP - MDN Web Docs - Mozilla
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same Origin ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This problem existed in v11 of the library and was solved with a PR request from me but totally ignored. https://github.com/Azure/azure-storage-net/pull/917
In short the allowedMethod is not an array of items but 1 single string with comma separated list of values. As this new library is mostly generated code I’m hesitating to fix it with a PR. But the culprit is at this line https://github.com/Azure/azure-sdk-for-net/blob/9ee2b1679bfb6b2ce680a67de546886a19ddae82/sdk/storage/Azure.Management.Storage/src/Generated/Models/CorsRule.Serialization.cs#L81
Instead of
foreach (var item in property.Value.EnumerateArray())
It should beforeach (var item in property.Value.EnumerateArray().SelectMany(value => value.Split(",")))
Also while you are at it please consider to add the PATCH verb to the list.
Thanks for the investigation @blueww ! Since this is a track1 SDK and not management plane SDK problem I will label it with track1 and close this issue as per the original post, this is a duplicate of https://github.com/Azure/azure-storage-net/issues/916. Any issue with the track1 sdk should be kept on this thread. Please reactivate if this is a track2 issue (v12).