Home / Azure

AzureTroubleshootingIntermediate

App Service access restrictions return 403 Forbidden: rule order, the SCM site, Front Door headers and subnet rules

Users, Front Door or a deployment pipeline get "403 - The web app you have attempted to reach has blocked your access". Find the rule that matched, or the missing one, and fix it without opening the app.

Deepak Bhardwaj7 min read

Applies toAzure App Service (Windows and Linux, including slots) and Azure Functions on App Service and Premium plans; Azure CLI 2.50+ (the --scm-default-action flag needs a recent CLI build)

Symptom

After someone adds or changes access restrictions, requests start to fail with:

  • Error 403 - Forbidden. The web app you have attempted to reach has blocked your access.
  • Front Door or Application Gateway reports the origin as unhealthy or passes the 403 through to users.
  • A deployment fails against <app>.scm.azurewebsites.net (Kudu) with 403, even though the main site works.
  • It works from your laptop but not from a VM, a partner or a pipeline. Or the other way round.

App Service checks access restrictions before your code runs, so your application logs show nothing. Look at the rule set first.

Step 1: dump the rules for the site and the SCM site

RG=rg-web-prod; APP=app-orders-prod
az webapp config access-restriction show -g $RG -n $APP -o json

Things to check in the output:

Field What it tells you
ipSecurityRestrictions Main site rules, applied in priority order (lowest number first). The first match wins.
ipSecurityRestrictionsDefaultAction What happens to traffic that matches no rule. Deny blocks everyone not listed.
scmIpSecurityRestrictions Rules for the Kudu/deployment site. These are separate from the main site rules.
scmIpSecurityRestrictionsUseMain true means the SCM site uses the main site rules.
scmIpSecurityRestrictionsDefaultAction Unmatched action for the SCM site.

Field names vary slightly between CLI and API versions, so check your build's output. Run the same command with --slot <name> for every slot. Access restrictions are slot-specific and are not swapped, so a slot that worked in staging can 403 in production after a swap. It can also go the other way.

Also check whether public access is switched off entirely:

az webapp show -g $RG -n $APP --query "{publicNetworkAccess:publicNetworkAccess, hostNames:enabledHostNames}" -o json

If publicNetworkAccess is Disabled, only private endpoint traffic gets in and the access restriction rules don't matter for public callers.

Step 2: find out what source IP App Service actually sees

Rules match the source IP of the TCP connection that reaches App Service. They don't match the user's original IP behind a proxy. The CIp column in the HTTP logs shows what App Service saw:

AppServiceHTTPLogs
| where TimeGenerated > ago(1h)
| where _ResourceId has "app-orders-prod"
| where ScStatus == 403
| summarize hits = count(), sample = any(CsUriStem) by CIp, CsHost, UserAgent
| order by hits desc

This needs a diagnostic setting that sends AppServiceHTTPLogs to Log Analytics. Without one, the portal's Diagnose and solve problems blade is the quickest option. You can also add a temporary allow rule for a known IP and test.

Typical surprises:

Caller IP App Service sees Rule you need
Users through Azure Front Door A Front Door backend IP, not the user's Service tag AzureFrontDoor.Backend plus an X-Azure-FDID header check
Application Gateway in a VNet subnet with the Microsoft.Web service endpoint Private address of the App Gateway subnet Subnet (virtual network) rule for the App Gateway subnet
Application Gateway without a service endpoint App Gateway public IP IP rule for that public IP
VM or AKS egress through NAT Gateway or Azure Firewall The NAT/firewall public IP IP rule for the egress IP, not the VM's private IP
GitHub-hosted runners or Azure DevOps Microsoft-hosted agents Changing public IPs Self-hosted runner with a fixed egress IP, or a private endpoint
On-premises users Corporate proxy or internet breakout IPs IP rules for every breakout range

Step 3: fix the common cases

Front Door in front of the app

Allowing only the service tag lets any Front Door profile reach your app, including someone else's. Always add the header filter with your profile's ID:

FDID=$(az afd profile show -g rg-edge -n afd-prod --query frontDoorId -o tsv)

az webapp config access-restriction add -g $RG -n $APP \
  --rule-name allow-frontdoor --action Allow --priority 100 \
  --service-tag AzureFrontDoor.Backend \
  --http-headers x-azure-fdid=$FDID

The reference documentation lists the parameter as --http-headers but some examples use --http-header. Check az webapp config access-restriction add -h on your CLI version. If you allow the service tag before you add the header, you get a short window where the app is open to all of Front Door.

Application Gateway or a VNet caller through a service endpoint

az webapp config access-restriction add -g $RG -n $APP \
  --rule-name allow-appgw --action Allow --priority 110 \
  --vnet-name vnet-hub --subnet snet-appgw --vnet-resource-group rg-network

The source subnet needs the Microsoft.Web service endpoint. The command checks this. Use --ignore-missing-endpoint true only when a different team will enable the endpoint and you're pre-staging the rule. Until the endpoint exists, traffic arrives from a public IP and the subnet rule doesn't match.

Deployments fail on the SCM site

Either give the SCM site its own rules or tell it to reuse the main site rules:

# Option A: separate rule for a self-hosted build agent's egress IP
az webapp config access-restriction add -g $RG -n $APP \
  --rule-name allow-build-agent --action Allow --priority 100 \
  --ip-address 203.0.113.40/32 --scm-site true

# Option B: SCM site follows the main site rules
az webapp config access-restriction set -g $RG -n $APP \
  --use-same-restrictions-for-scm-site true

Option B is wrong if the main site only allows Front Door. Front Door doesn't proxy the SCM host, so every deployment would be blocked.

Warning

Don't fix a pipeline 403 by setting --scm-default-action Allow. That exposes Kudu, which can read app settings and deploy code, to the internet. Add a specific rule, or deploy through a private endpoint from a self-hosted agent.

A rule exists but never matches

  • Priority: a broad Deny at priority 100 beats a specific Allow at 200. Give specific allows lower numbers than broad denies.
  • CIDR typos: 10.20.0.0/16 vs 10.2.0.0/16. Single IPs need /32 in some tooling. The CLI accepts both.
  • IPv6: clients that reach the app over IPv6 don't match IPv4 rules. Check CIp in the logs.
  • Limits: a rule takes up to 8 IP ranges or service tags. Check the current per-site rule limit before you script hundreds of entries.

Step 4: remove a bad rule quickly

az webapp config access-restriction remove -g $RG -n $APP --rule-name block-all-temp
az webapp config access-restriction remove -g $RG -n $APP --rule-name allow-build-agent --scm-site true

Caution

az webapp config access-restriction set --default-action Allow restores access instantly but removes your protection completely. Use it only as a timed emergency step with an incident note, then put the correct rules back.

Prevent it next time

  • Manage access restrictions in Bicep or Terraform (ipSecurityRestrictions, scmIpSecurityRestrictions in siteConfig) so slots and environments get identical, reviewed rules.
  • Name every rule (--rule-name) with its owner and purpose. "allow-1" is no help at 3 a.m.
  • Keep the AppServiceHTTPLogs diagnostic setting on and alert on a jump in ScStatus == 403:
AppServiceHTTPLogs
| where TimeGenerated > ago(15m) and ScStatus == 403
| summarize blocked = count() by _ResourceId, bin(TimeGenerated, 5m)
| where blocked > 50
  • For apps that must never be public, use a private endpoint and publicNetworkAccess = Disabled instead of a long IP allow list.
  • After every swap, run access-restriction show against both slots as a release check.