An Azure service that provides an event-driven serverless compute platform.
Hi Milena,
This is desired behavior, not a bug.
The x-ms-auth-internal-token header is automatically injected by Azure App Service when:
1. Authentication is enabled on the App Service
2. The request originates from within the same App Service environment (internal calls)
3. CORS is configured, which signals to Azure that cross-origin requests should be handled
When you remove CORS from Azure configuration, the platform no longer recognizes these as internal/trusted requests, so it stops injecting the authentication token.
Here are some suggested solutions, rather than making the HealthCheck public:
1. Use IP restriction - Allow health check endpoint from Azure's internal IP ranges
2. Custom health check endpoint - Create a separate /health-internal endpoint that bypasses auth, restricted to local/internal IPs only
3. Configure CORS minimally - Re-add CORS with restrictive settings just to re-enable the internal token injection
4. Use App Service's built-in health check - Configure it in Azure Portal under Monitoring > Health check, which automatically bypasses auth
5. Anonymous auth for specific path - In your middleware, allow anonymous access only for /health or /healthzpaths
Recommended approach:
// In your middleware
if (context.Request.Path.StartsWithSegments("/health") &&
context.Connection.LocalIpAddress?.Equals(context.Connection.RemoteIpAddress) == true)
{
// Allow health check from localhost/internal
await next();
}
Or use Azure's native health check feature which doesn't require the auth token.