Cloud

Azure Front Door: diagnose a redirect loop before disabling HTTPS

A production runbook for isolating a loop across Azure Front Door, redirect rules and an App Service origin, then correcting host or protocol handling with validation and rollback.

14 Oct 2026 azureazure-front-doorfront-doorapp-servicehttphttpsredirectoriginheadersobservabilityrunbookrollbackproduction

After an Azure Front Door route or origin host header change, https://app.example.com/login returns too many redirects. The endpoint remains healthy, the public certificate is valid, and the health probe still passes. Disabling HTTPS in the application or removing the edge redirect can stop the loop, but only by weakening transport or creating different behavior on different paths.

The running case is an App Service behind Azure Front Door Standard/Premium. Front Door terminates TLS, calls the origin over HTTPS, and forwards either the public host or the origin host according to configuration. The application then builds URLs from the host and scheme it believes it received. The goal is to identify which component emits each Location, correct one boundary, and validate HTTP, HTTPS, and authentication journeys before promotion or rollback.

Freeze the redirect chain

Do not begin by letting a browser follow redirects automatically. Capture every hop, status, Location, host, and correlation header. Use an uncached URL and a unique identifier so the same request can be found in Front Door and application evidence.

bash 01-capture-redirect-chain.sh
HOST="app.example.com"
PATH_TO_TEST="/login?redirect=%2Forders%2F42"
CORRELATION_ID="redirect-$(date -u +%Y%m%dT%H%M%SZ)"

curl --silent --show-error --dump-header - --output /dev/null --max-redirs 0 -H "x-correlation-id: $CORRELATION_ID" "https://$HOST$PATH_TO_TEST"

curl --silent --show-error --location --max-redirs 10 --trace-ascii redirect-trace.txt -H "x-correlation-id: $CORRELATION_ID" "https://$HOST$PATH_TO_TEST" --output /dev/null

Record exact repetitions. A bounce between app.example.com and app-prod.azurewebsites.net points to loss of the public host. Repetition of the same HTTPS URL suggests the origin still believes it received HTTP. Alternation between two paths such as /login and /signin points toward application or authentication rules.

Preserve a healthy control such as /health/ready and an unauthenticated URL as well. If only sign-in loops, callback contracts, cookies, and URL generation are more likely than a global Front Door route.

Attribute the first hop

A 301, 302, 307, or 308 does not identify its producer. Compare three paths with the same method: the public URL over HTTP, the public URL over HTTPS, and the direct origin with the expected host when network policy allows it from a diagnostic location.

bash 02-compare-edge-origin.sh
PUBLIC_HOST="app.example.com"
ORIGIN_HOST="app-prod.azurewebsites.net"
PATH_TO_TEST="/login"

curl -sS -D - -o /dev/null --max-redirs 0 "http://$PUBLIC_HOST$PATH_TO_TEST"

curl -sS -D - -o /dev/null --max-redirs 0 "https://$PUBLIC_HOST$PATH_TO_TEST"

curl -sS -D - -o /dev/null --max-redirs 0 -H "Host: $PUBLIC_HOST" "https://$ORIGIN_HOST$PATH_TO_TEST"

Do not expose the origin publicly to run this test. Use an existing authorized runner or administration path, or rely on application logs when direct access is closed. The direct request separates edge and origin; it must not create a new production path.

If Front Door redirects HTTP to HTTPS once and the HTTPS request loops only after reaching the origin, keep the edge redirect. If the first incorrect Location appears without a matching application request, inspect the route and its rule sets first.

Read the deployed Front Door state

Export the current state before correction: route domains, accepted protocols, forwarding protocol, rule sets, origin group, and originHostHeader. A correct IaC definition on a branch is not evidence of effective state.

bash 03-export-front-door-state.sh
RG="rg-edge-prod"
PROFILE="afd-platform-prod"
ENDPOINT="edge-prod"
ROUTE="app-route"
ORIGIN_GROUP="app-origins"
ORIGIN="app-weu"

az afd route show --resource-group "$RG" --profile-name "$PROFILE" --endpoint-name "$ENDPOINT" --route-name "$ROUTE" --output json > route-before.json

az afd origin show --resource-group "$RG" --profile-name "$PROFILE" --origin-group-name "$ORIGIN_GROUP" --origin-name "$ORIGIN" --output json > origin-before.json

az afd rule-set list --resource-group "$RG" --profile-name "$PROFILE" --output json > rule-sets-before.json

A Front Door redirect action returns a response directly to the client. A forward route sends the request to the origin, which can then issue another redirect. Inspect rule order, Continue or Stop behavior, destination protocol, host, and path. Two individually reasonable rules can loop when they rewrite each other.

Review originHostHeader separately. Front Door can leave it blank to preserve the host requested by the client. The origin must then know that custom domain. Forcing the *.azurewebsites.net host can make the application generate absolute URLs for the technical domain, disturb cookies, or break callbacks. Do not change this setting until the origin is proven to accept the public host.

Verify the host and protocol contract in the application

Front Door supplies headers including X-Forwarded-Host and X-Forwarded-Proto. The application must interpret them only from a trusted proxy and before HTTPS redirection or authentication middleware. Otherwise, it can receive a valid HTTPS request through Front Door, reconstruct it as HTTP, and redirect forever to the URL already requested.

Temporarily add a structured log without sensitive content to expose what the runtime actually uses.

json 04-origin-request-evidence.json
{
"correlation_id": "redirect-20261014T141500Z",
"request_host": "app.example.com",
"request_scheme": "https",
"forwarded_host": "app.example.com",
"forwarded_proto": "https",
"path": "/login",
"status": 302,
"location_host": "app.example.com",
"location_scheme": "https",
"redirect_component": "authentication-middleware"
}

Do not log cookies, authorization codes, or complete query strings. When a framework requires known proxies or networks, configure the trust boundary explicitly rather than accepting every X-Forwarded-* header from the internet.

Then verify the App Service custom domain, identity provider callback URLs, and cookie domain plus Secure and SameSite attributes. Correcting the scheme while leaving a callback on azurewebsites.net only moves the incident.

Correct one boundary through a canary

Choose the correction supported by evidence: remove a duplicate Front Door rule, preserve the public host, register the custom domain on the origin, or process forwarded headers before application redirection. Avoid changing the route, host header, and middleware together because the restored contract would be impossible to identify.

The canary should use a controlled hostname or path through the new configuration without moving all traffic. Replay a small matrix: public HTTP, public HTTPS, anonymous page, sign-in, callback, and a prepared non-idempotent POST with no business execution.

yaml 05-redirect-canary-gate.yml
expected:
http_public:
  redirects: 1
  final_scheme: https
  final_host: app.example.com
https_public:
  redirects_max: 1
  final_status: 200
  technical_origin_exposed: false
authentication:
  callback_host: app.example.com
  session_cookie_secure: true
  redirect_budget: 4
health:
  origin_healthy: true
  application_dependency_check: passed

stop_when:
- same_url_seen_twice
- redirect_to_azurewebsites_host
- callback_host_mismatch
- login_succeeds_but_session_cookie_is_lost
- origin_health_regresses

A final 200 is insufficient if the client crossed nine redirects. Count hops, prove that the technical host never appears, and retain traces with the tested configuration version.

Decide promotion, hold, or rollback

Promote when HTTP produces a single move to HTTPS, HTTPS does not loop, the origin sees the expected host and scheme, and authentication preserves the callback and cookie. Then monitor 3xx rate, sign-in errors, and origin health by route and domain.

Hold the canary when the origin cannot yet accept the public host or the framework cannot safely bound trust in forwarded headers. Document the target contract and correct the application before moving global traffic.

Roll back the most recent change that owns the faulty boundary: rule set version, previous originHostHeader, or previous application middleware. Replay the same matrix after rollback. Do not disable HTTPS globally to produce a responding page, and do not retain a public origin as a bypass.

Conclusion

A Front Door loop is not an abstract redirect issue. It is an observable disagreement about host, scheme, or ownership of the Location between edge and origin.

The production decision should remain narrow: correct the redirecting rule, preserve the public host, restore safe handling of X-Forwarded-Proto, or return to the previous configuration. The change is valid when every hop has an owner, HTTPS remains end to end, and rollback passes the same matrix without surprise.