Azure functions ignores entries for CORS allowed origins
I'm trying to deploy Azure with resource templates. In my template.json I want to set up allowed origins to all:
"siteConfig": {
"cors": {
"allowedOrigins": [
"*"
]
},
The problem is that Azure anyway creates by default additional entries:

And after that I have problem with CORS, "*" rule seems to be ignored if there are any specific cors entries. So I need to manually delete these three added by Azure. Do you have any idea how I can automatically get rid of them or somehow else setup allowed origins to all?
Which CLI command are you using and which service are you creating CORS rules for?
I'm creating a resource group with command:
az group deployment create --resource-group testrg --template-file template.json --parameters parameters.json --mode Complete
and within this group, i'm creating an Azure Function, triggered by HTTP binding. I want to create CORS rules for this function.
In template.json i'm describing this Azure Function, and as I have shown before, I'm adding one entry for cors allowed origin "*".
Azure however adds three additional allowed origins: https://functions.azure.com https://functions-staging.azure.com https://functions-next.azure.com
And in the end, only these three origins are allowed for CORS, the general rule for all origins is then ignored.
edit: This is also really problematic because Azure CLI currently does not provide an option to manage CORS entries for function apps --> https://github.com/Azure/azure-cli/issues/4565 I would like to have whole setting up an infrastructue in an automated way but I cannot workaround this issue.
This sounds like a service limitation. @panchagnula can you confirm?
Is there an ETA for an enhancement where the option to disable the default CORS rules will be supplied via ARM template (i.e. non-manual methods) for customers who do not require them?
@jrgithub have you tried this command? https://docs.microsoft.com/en-us/cli/azure/webapp/cors?view=azure-cli-latest , this available for functonapps as well https://docs.microsoft.com/en-us/cli/azure/functionapp/cors?view=azure-cli-latest -
@jrgithub have you tried this command? https://docs.microsoft.com/en-us/cli/azure/webapp/cors?view=azure-cli-latest , this available for functonapps as well https://docs.microsoft.com/en-us/cli/azure/functionapp/cors?view=azure-cli-latest -
Unfortunately this command does not work for me with web apps. The azure terminal outputs an updated allowedOrigins key:value but the host continues to generate a cors error.
@ahmelsayed - can you please take a look & help out here please. Are there any special CORS setting that are missing here?
Hi, I'm getting same issue where these three default entries remains and CORS headers don't get reflect in response. I'm using node-js based function and I could temporarily achieve the desired result by removing all CORS rules which were default added ( and did not add a new entry with *) additionally I added CORS headers manually in response object within nodeJS function and then the returning response had these headers reflecting..
so the only question remains is " Can these rules be removed programatically or using ARM template" so no manual intervention required.
R's navin
- will not remove all the entries, in Arm Template you should use an [] to remove all the rules, you can try by using resources.azure.com, & edit the Site Config CorRules property.
Tried with below setting in template after having a word with azure guys on a service ticket call.
"resources": [{ "apiVersion": "2016-08-01", "name": "[parameters('appName')]", "type": "Microsoft.Web/sites", "properties": { "name": "[parameters('appName')]", "siteConfig": { "cors": { "allowedOrigins": ["*"] }, . . . . . .
This seems to be working, I didn't try it earlier as the very first comment convinced me it wouldn't work. ( Just to mention, I have CORS headers set in my function explicitly and they've started getting honoured after this template change )
looks like a solution to me!!
i am closing this since this - we have a CLI command for this that has been released.