Azure Function HealthCheck does not inject x-ms-auth-internal-token

Anonymous
2025-10-03T11:24:53.46+00:00

When CORS is set, HealthCheck normally injects x-ms-auth-internal-token into request header.

Due to some needed changes, we removed CORS from the Azure setup and moved this logic into a middleware. This removal of CORS caused HealthCheck to be Degraded due to 401s returned.
Upon logging the request headers I noticed that x-ms-auth-internal-token is not sent when CORS is removed.
Our current solution is to remove this security check from the HealthCheck and make it public.

Is this desired behavior or a bug?

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

0 comments No comments

Answer accepted by question author
David Broggy 6,801 Reputation points MVP
2025-10-03T12:50:16.8466667+00:00

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.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Thomas Döör - Mover 0 Reputation points
    2026-09-15T13:22:10.94+00:00

    I hosting a .net 10 web app on Linux, and I see the header x-ms-auth-internal-token header only when starting the app.
    When running the app the header is no longer there. Why is that?

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.