EMA leg 2 strips the trailing slash from the authorization server URL, so audience no longer equals the issuer

Abierto Apto para principiantes
#3,098 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Empieza en core/auth/ema/emaFlow.ts, en la construcción de la audiencia de la línea 82, y luego sigue cómo se descubre la URL del servidor de autorización y se pasa a EMA leg 2. Comprueba si existen pruebas que cubran el intercambio de tokens y añade o actualiza un caso en el que el issuer termine en /. Se considera terminado cuando la audiencia enviada al IdP coincide exactamente con el issuer anunciado, incluida la barra final.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
Which version line?

v2 — current (@modelcontextprotocol/inspector@latest)

Which client?

Web

Inspector version

2.17.0

Node version

v24.22.3

Operating system (and browser, for the web client)

macOS 26.7.3, Chrome 158

Transport

Streamable HTTP

MCP server under inspection
  • Server: a small xmcp server (name "xmcp server", version 0.1.0) over Streamable HTTP at http://localhost:3001/mcp, protected by Auth0 as the authorization server. Source: https://github.com/auth0-samples/mcp-workshop (branch step-5-cross-app-access). It only exposes tools.
  • Protocol era: legacy (as shown in the Inspector's Server Implementation panel). Protocol 2025-11-25, session-based.
  • OAuth: yes. Enterprise-managed authorization (EMA) is on. The IdP is Okta, and the resource authorization server is Auth0 (issuer https://tenant.eu.auth0.com/, with a trailing slash). The server's protected resource metadata lists that issuer.
Steps to reproduce
  1. Use an IdP with XAA (Okta) and a resource AS whose issuer ends with / (Auth0).
  2. Register the resource AS issuer with the slash at the IdP.
  3. In the Inspector, enable enterprise-managed authorization and connect.
  4. Leg 2 fails with invalid_target. The network export shows audience without the slash.
Expected behavior

audience equals the authorization server's issuer exactly as the metadata advertises it. RFC 8414 treats the issuer as an exact string, and the ID-JAG's aud must match the resource AS's issuer, so https://x/ and https://x are different values.

Actual behavior

In enterprise-managed authorization (EMA) leg 2, the Inspector sends the IdP token exchange an audience built like this:

// core/auth/ema/emaFlow.ts, line 82
const audience = ctx.resourceAsUrl.href.replace(/\/$/, "");

If the resource authorization server's issuer ends with /, the slash is dropped. Auth0 issuers always end with / (for example https://tenant.eu.auth0.com/), and the protected resource metadata lists it that way:

{ 
  "resource": "http://localhost:3001/mcp", 
  "authorization_servers": ["https://tenant.eu.auth0.com/"] 
}

The request the Inspector sent to Okta's /oauth2/v1/token (secrets removed):

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
requested_token_type=urn:ietf:params:oauth:token-type:id-jag
audience=https://tenant.eu.auth0.com          <- slash removed
resource=http://localhost:3001/mcp
subject_token_type=urn:ietf:params:oauth:token-type:id_token
scope=tool:...

Okta answers 400 invalid_target ("The token request contains an invalid target."), because the registered issuer is https://tenant.eu.auth0.com/.

Logs, errors, or screenshots

[
{
"request": "GET http://localhost:3001/.well-known/oauth-protected-resource",
"status": 200,
"response": {
"resource": "http://localhost:3001/mcp",
"authorization_servers": ["https://tenant.eu.auth0.com/"],
"bearer_methods_supported": ["header"],
"scopes_supported": ["openid", "profile", "email"]
}
},
{
"request": "POST https://idp.example.com/oauth2/v1/token",
"contentType": "application/x-www-form-urlencoded",
"body": {
"grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
"requested_token_type": "urn:ietf:params:oauth:token-type:id-jag",
"audience": "https://tenant.eu.auth0.com",
"resource": "http://localhost:3001/mcp",
"subject_token": "",
"subject_token_type": "urn:ietf:params:oauth:token-type:id_token",
"client_id": "",
"client_secret": "",
"scope": "tool:whoami tool:order_pizza"
},
"status": 400,
"response": {
"error": "invalid_target",
"error_description": "The token request contains an invalid target."
}
}
]

The web UI shows the following error:

Failed to connect to "xmcp-demo"
EMA legs 2–3 (resource token mint): EMA leg 2 (IdP token exchange for ID-JAG): Token exchange failed: invalid_target - The token request contains an invalid target.

Already prototyped a fix?

Send ctx.resourceAsUrl.href unchanged, or better, the issuer value from the discovered authorization server metadata. If a normalization was added for a particular server, make it opt-in per server.

Before you submit
  • I searched existing issues and this is not a duplicate.
  • This is not a security vulnerability report (those go through the private advisory process).
Lenguaje dominante
TypeScript
Estrellas
11.3k
Forks
1.6k
Merge medio
2 h 31 min
PR fusionados (30 d)
118

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de modelcontextprotocol/inspector

Todos los issues de modelcontextprotocol/inspector

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.