Foundry hosted agents forward their Azure bearer token to any origin a toolbox proxy names

A malicious or compromised Foundry toolbox proxy can make a hosted agent send its Azure bearer token for https://ai.azure.com to any origin it chooses. The agent's MCP transport follows a message endpoint advertised over SSE to another origin, and its token handler attaches the token to every request without checking where it is going.

CVE
Not assigned
Weakness
CWE-522
Vendor
Microsoft
Product
Microsoft Agent Framework, Foundry hosting (Microsoft.Agents.AI.Foundry.Hosting)
Affected
Audited at commit 5eb3eb745e16324ac7bffb1dbe006d8f13c8d993
With ModelContextProtocol 1.2.0
Fixed in
Fixed by Microsoft (notified 30 October 2026); no fixed version published

Overview

Microsoft Foundry hosted agents can call tools through a Foundry toolbox, which the agent container reaches as a Model Context Protocol (MCP) server behind a Foundry-operated proxy. The container authenticates to that proxy with an Azure bearer token for the https://ai.azure.com/.default scope.

FoundryToolboxService.OpenToolboxAsync() in Microsoft.Agents.AI.Foundry.Hosting builds its MCP HttpClientTransport without the cross-origin controls that the sibling DefaultMcpToolHandler applies. The bearer token is added by FoundryToolboxBearerTokenHandler, which stamps Authorization onto every outgoing request without checking where the request is going.

Together these let a malicious or compromised toolbox proxy steer the hosted agent into sending its bearer token to a different origin of the attacker's choosing.

Affected configurations

The issue applies to hosted agents that open a Foundry toolbox through FoundryToolboxService, as audited at commit 5eb3eb745e16324ac7bffb1dbe006d8f13c8d993 with ModelContextProtocol 1.2.0.

The attacker must control, or be able to impersonate, the toolbox proxy endpoint the agent is configured to use. The proxy already receives the token legitimately; the issue is that it can redirect that token to any other origin, so a compromise of the proxy, or of anything able to answer on its behalf, becomes a credential leak to an arbitrary host.

Details

OpenToolboxAsync() creates the transport with the bearer-token handler in front of a default HttpClientHandler, and leaves the transport mode at its default:

var handler = new FoundryToolboxBearerTokenHandler(credential, featuresHeader)
{
    InnerHandler = new HttpClientHandler()
};
var httpClient = new HttpClient(handler);

var transportOptions = new HttpClientTransportOptions
{
    Endpoint = endpoint,
    Name = toolboxName,
};
var transport = new HttpClientTransport(transportOptions, httpClient);

There is no origin-pinning handler and no transport mode override, so the transport runs in AutoDetect mode. In that mode the MCP client first tries Streamable HTTP and, if the server declines, falls back to the legacy HTTP+SSE transport. In the legacy transport the server announces where the client should POST its messages with an endpoint event, and the client accepts an absolute URL on any origin.

Every request the transport sends passes through FoundryToolboxBearerTokenHandler.SendAsync(), which fetches a token and attaches it unconditionally:

var token = await this._credential
    .GetTokenAsync(s_tokenContext, cancellationToken)
    .ConfigureAwait(false);

request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);

Excerpt from FoundryToolboxBearerTokenHandler.cs, Microsoft.Agents.AI.Foundry.Hosting, © Microsoft.

The handler never compares the request's origin with the configured toolbox endpoint, so the token is attached to the cross-origin message POST exactly as it is to requests for the real proxy.

Impact

An attacker who controls the toolbox proxy response receives a bearer token for https://ai.azure.com/.default issued to the hosted agent's identity, on a server of their choosing. With it they can call Foundry APIs as that agent until the token expires.

The same requests also carry the Foundry-Features header and, when present, the per-call x-agent-foundry-call-id and W3C trace context, which disclose further details of the hosted environment.

Proof of concept

The behavior was confirmed with a harness that compiles the real FoundryToolboxBearerTokenHandler.cs and its dependency HostedCallContext.cs unchanged, reproduces the transport construction from OpenToolboxAsync() line for line, and runs against the same ModelContextProtocol 1.2.0 package. The only stub is a credential that returns a sentinel string in place of a live token.

The harness runs two local servers on different origins. The first plays the configured toolbox proxy: it answers the Streamable HTTP probe with 405, which makes the client fall back to HTTP+SSE, and then advertises a message endpoint on the second origin. The second server records the request it receives. It captured a POST carrying Authorization: Bearer with the sentinel token and the Foundry-Features: Toolboxes=V1Preview header.

The harness is held privately and is not included in this write-up.

Remediation

Microsoft notified us on 30 October 2026 that a fix had been issued. Keep Microsoft.Agents.AI.Foundry.Hosting and its dependencies on their latest releases. A CVE has been requested and will be added here once assigned.

For anyone building a similar MCP client, the controls that close this class of issue are the ones DefaultMcpToolHandler already applies:

  • Pin requests to the configured toolbox origin, and refuse or strip credentials from any request to another origin, including message endpoints advertised over SSE.
  • Disable automatic redirects on the inner handler.
  • Set the transport mode explicitly to Streamable HTTP so a server cannot force the legacy SSE fallback.

As defense in depth, FoundryToolboxBearerTokenHandler should attach the token only when the request URI matches the configured proxy origin.

Disclosure timeline

  1. Reported to Microsoft (MSRC)
  2. MSRC case 134644 opened
  3. Microsoft confirmed the reported behavior
  4. Bounty awarded
  5. Microsoft notified that a fix had been issued
  6. Microsoft reviewed disclosure
  7. Advisory published

Revision history

  1. Initial publication

Machine-readable: LVL0X00-2026-0008.json