Microsoft Defender for Cloud · Azure App Service
CORS should not allow every resource to access API Apps
Written and reviewed by Emnode · Last reviewed
What does the recommendation "CORS should not allow every resource to access API Apps" check?
Flags an App Service API app whose Cross-Origin Resource Sharing configuration lists the wildcard origin '*' in allowedOrigins, meaning a browser on any site can issue cross-origin requests to the app's endpoints. It inspects only the platform-level CORS setting exposed under the app's cors property. It does not read CORS headers your own application code emits from middleware, nor does it check which HTTP methods or headers you allow, whether credentials are permitted, or whether your authentication and authorisation are sound. A specific but overly broad origin list still passes; only the literal '*' is caught. The original recommendation, '[Deprecated]: CORS should not allow every resource to access your API App', has been deprecated by Microsoft, so newer subscriptions surface the equivalent App Service check 'App Service apps should not have CORS configured to allow every resource to access your apps'.
Why does "CORS should not allow every resource to access API Apps" matter?
A wildcard CORS origin tells browsers that script on any website may read your API's responses. If a user with an active session visits an attacker's page, that page can call your API in the user's context and exfiltrate whatever the responses contain. For an API app this often means account data, tokens echoed in payloads or internal records that were never meant to leave a trusted front end. CORS is not an authentication control, but a permissive policy widens the blast radius of any session-handling or token weakness and turns a single phishing click into data theft. Restricting origins to the front ends you actually operate closes that browser-driven path and keeps cross-site abuse out of the picture.
How do I fix "CORS should not allow every resource to access API Apps"?
- List the current origins with 'az webapp cors show --name <app> --resource-group <rg>' and confirm the entry '*' is present.
- Remove the wildcard and add only the front-end origins you own: 'az webapp cors remove --name <app> --resource-group <rg> --allowed-origins' (with no value clears the list), then 'az webapp cors add --name <app> --resource-group <rg> --allowed-origins https://app.contoso.com https://admin.contoso.com'. In Bicep, set the site's siteConfig.cors.allowedOrigins array to those explicit origins instead of ['*'].
- Enforce it going forward by assigning the built-in policy. Look the definition up by display name so you never hardcode a GUID: pid=$(az policy definition list --query "[?displayName=='App Service apps should not have CORS configured to allow every resource to access your apps'].name" -o tsv); az policy assignment create --name no-wildcard-cors --policy "$pid" --scope <scope>.
Remediation script · bash
SUB="/subscriptions/00000000-0000-0000-0000-000000000000"
RG="rg-app-prod"
# Harden every app that is not already HTTPS-only.
for app in $(az webapp list -g "$RG" \
--query "[?!httpsOnly].name" -o tsv); do
# 1. Force HTTPS on the site itself.
az webapp update -g "$RG" -n "$app" --https-only true
# 2. Turn off the remote debugger.
az webapp config set -g "$RG" -n "$app" --remote-debugging-enabled false
# 3. Drop any wildcard CORS origin (replace with your own origins after).
az webapp cors remove -g "$RG" -n "$app" --allowed-origins '*'
echo "$app: HTTPS forced, remote debugging off, wildcard CORS removed"
done
# Ratchet it shut: deny any future app that is not HTTPS-only.
# Look the built-in policy up by display name, never hardcode the GUID.
pid=$(az policy definition list \
--query "[?displayName=='App Service apps should only be accessible over HTTPS'].name" -o tsv)
az policy assignment create \
--name deny-appservice-http \
--policy "$pid" \
--scope "$SUB" Full walkthrough (console steps, edge cases and verification) in the lesson Harden Azure App Service apps.
Is "CORS should not allow every resource to access API Apps" a false positive?
A genuinely public, unauthenticated read-only API that serves only non-sensitive data and is consumed by browser code on origins you cannot enumerate in advance (for example a public reference feed or an open dataset) may legitimately keep '*'. Because the policy cannot tell a deliberate public API from an accidental wildcard, it still flags. Confirm the endpoints expose nothing session-scoped or sensitive, then exempt that app rather than tightening origins you genuinely cannot predict.
More Azure App Service controls
- API App should only be accessible over HTTPS
- CORS should not allow every resource to access Web Applications
- Ensure API app has Client Certificates Incoming client certificates set to On
- FTPS should be required in API apps
- FTPS should be required in web apps
- Java should be updated to the latest version for API apps
- Managed identity should be used in API apps
- Managed identity should be used in web apps
- Microsoft Defender for App Service should be enabled
- PHP should be updated to the latest version for API apps
- Python should be updated to the latest version for API apps
- Remote debugging should be turned off for API App