AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

CORS Wild Card support in Azure

Open OzBob opened this issue 8 years ago • 15 comments

The apicors azure portal end point does not accept https://*.domain.com/ as a valid 'allowed origin'

A little red exclamation appears and says it must be in the format [HTTP:HTTPS]://[www.]domain.[TLD][:portnumber]


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

OzBob avatar Jun 20 '18 09:06 OzBob

@guardrex should that info go in an Azure doc? @OzBob where do you think it should go?

Rick-Anderson avatar Jun 20 '18 14:06 Rick-Anderson

@OzBob so ...

https://domain.com/

or just ...

https://domain.com

doesn't work?

guardrex avatar Jun 20 '18 14:06 guardrex

Correction: https://stackoverflow.com/a/49943569/1586498 and https://github.com/aspnet/CORS/pull/76 say that it is now supported in code.

I still can't get it to be a valid origin in the azure portal webapp api CORS form. image

@Rick-Anderson is there docs on how to use that CORS feature of the Azure Portal?

OzBob avatar Jun 21 '18 04:06 OzBob

@SyntaxC4 @kichalla @pranavkm would that go in an Azure doc?

Rick-Anderson avatar Jun 21 '18 15:06 Rick-Anderson

@CamSoper

is there docs on how to use that CORS feature of the Azure Portal?

Rick-Anderson avatar Oct 25 '18 02:10 Rick-Anderson

Support for wildcard subdomains is a feature of the ASP.NET Core CORS middleware, not actually part of the CORS (fetch) spec. My guess is the Azure service (is this Azure App Services) does not support this feature.

pranavkm avatar Oct 25 '18 16:10 pranavkm

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

Rick-Anderson avatar Jan 22 '19 22:01 Rick-Anderson

I still don't understand how you want us to get around this issue. Azure Static App creates a dynamic url for each environment so how can it call an azure function if the URL changes? Is it just unusable?

URL example: https://smoked-bacon-[032fe1c0f-2.eastus2].azurestaticapps.net (the middle section changes for each deployment)

weisssean avatar Oct 28 '20 19:10 weisssean

Any news on it? vercel by example create random subdomains!

imclint21 avatar May 28 '21 16:05 imclint21

@weisssean @OzBob @clintnetwork if you can recommend the appropriate azure document, I'll transfer this issue to Azure and try to get some help.

Rick-Anderson avatar May 28 '21 19:05 Rick-Anderson

Documents that mention CORS that would benefit from noting the limitations of the UI in the portal and maybe (i haven't tested it yet) how to use the Azure CLI instead:

https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-rest-api#add-cors-functionality https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0

Azure CLI CORS commands: https://docs.microsoft.com/en-us/cli/azure/webapp/cors?view=azure-cli-latest#az_webapp_cors_add

OzBob avatar May 31 '21 01:05 OzBob

@OzBob can you open issues there? This doesn't seem to be related to ASP.NET Core

Rick-Anderson avatar May 31 '21 02:05 Rick-Anderson

Found the solution for this issue -- APIM CORS with Wild Card

  1. Remove CORS policy from APIM for all operations of service.

  2. Add an OPTIONS operation for those APIs that needs CORS with wildcards. E.g.,

2.1. With perspective to the operation GET /service/items/{id}

2.2. Add in APIM a new corresponding operation OPTIONS /service/items/{id}

  1. Configure the service with the customized CORS policy, like MicrosoftTeams-image (1)
  2. app.UseCors(this.allowSpecificOrigins);

OlivierShi avatar Jul 14 '22 15:07 OlivierShi

I still don't understand how you want us to get around this issue. Azure Static App creates a dynamic url for each environment so how can it call an azure function if the URL changes? Is it just unusable?

URL example: https://smoked-bacon-[032fe1c0f-2.eastus2].azurestaticapps.net (the middle section changes for each deployment)

First of all, even with your example case, just what would be your proposal for a wildcard'ed solution? *.azurestaticapps.net? So, like, the entire static apps world? Right, so, you actually have two problems, how to wildcard CORS and how to better control the subdomain names of your static apps so that they are more predictably patterned.

This: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-rest-api#how-do-i-set-allowed-origins-to-a-wildcard-subdomain

... claims that wildcard origin allowances are applicable via the CLI, even if the Azure portal UX doesn't yet allow it.

And then, controlling your static app URLs, you probably need an actual wildcard certificate of your own (as would anyone else looking to configure multiple subdomains. And then, this; https://learn.microsoft.com/en-us/azure/static-web-apps/custom-domain

cbrunettigg avatar May 03 '23 18:05 cbrunettigg

Actually @cbrunettigg, what I was suggesting was to wildcard the part that changes when a static web app gets deployed, so: https://smoked-bacon-[*].azurestaticapps.net/.

weisssean avatar May 03 '23 18:05 weisssean