[v2] Client accepts a parent-path protected resource metadata, is this intended given RFC 9728?

Ouverte
#3,077 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #3169 par @bbdu3 — fermée sans fusion

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
43/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
typescript
Domaine
authentication

Piste de recherche

Start with packages/core-internal/src/shared/authUtils.ts, especially selectResourceURL and checkResourceAllowed, then compare the current behavior with RFC 9728 §3.3 and the linked issues #638, #2751, and #3041. The issue asks whether parent-path resources should be accepted and whether any change should allow an opt-in for lenient matching; the expected resolution is a maintainer decision on that behavior and its compatibility implications.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

v2
What happened?

Question

Is it intended that the client accepts Protected Resource Metadata (PRM) whose resource is a parent path of the server URL? And if so, how should that be reconciled with RFC 9728 §3.3?

Current behaviour

selectResourceURL validates resourceMetadata.resource with checkResourceAllowed, which accepts any same-origin resource whose path is a prefix of the server URL's path (authUtils.ts). The less specific URL is then returned and sent as the RFC 8707 resource parameter.

Example:

  • Server URL: https://host/mcp/gateway/bundle/my-bundle
  • 401 with WWW-Authenticate: Bearer resource_metadata="https://host/mcp/gateway/.well-known/oauth-protected-resource/bundle/my-bundle"
  • PRM: {"resource": "https://host/mcp/gateway", ...}

The SDK accepts this and requests a token for https://host/mcp/gateway. VS Code rejects the same metadata (oauth.ts: "Per RFC 9728, these MUST match"), so a server that works with SDK-based clients fails in VS Code.

Why I'm asking

RFC 9728 §3.3:

If the protected resource metadata was retrieved from a URL returned by the protected resource via the WWW-Authenticate resource_metadata parameter, then the resource value returned MUST be identical to the URL that the client used to make the request to the resource server. If these values are not identical, the data contained in the response MUST NOT be used.

§7.3 gives impersonation as the reason for the identical-match rule. The MCP spec adopts RFC 9728 and asks clients to "provide the most specific URI that they can" (2025-11-25, Canonical Server URI).

The prefix matching was introduced in #638. Its description says resource URIs are used as-is "to allow having different MCP servers under different subpaths … w/o spilling their resource authorization to each other". It also warns that a non-specific resource lets a "bad apple" server benefit from resource confusion with its siblings. Accepting a parent-path resource from the PRM seems to allow exactly that: a server at /a/b can get the client to request a token for /a. I couldn't find a rationale for the prefix rule in the PR or its review.

#2751 already notes in passing that this leniency hides non-compliant server setups.
#3041 covers the trailing-slash asymmetry in the same function. Neither asks whether the prefix rule itself is intended.

Questions

  1. Is accepting a parent-path resource on the client side intentional?
  2. If yes, is it meant to apply to metadata discovered via WWW-Authenticate, where §3.3 requires identity? Or only to the root well-known fallback?
  3. If no, would you accept a change that makes selectResourceURL require equality? This would be normalized equality, tolerant of a trailing slash as in #3041, possibly with an opt-in for lenient matching to avoid breaking existing servers.

Note: downstream clients reuse checkResourceAllowed in their own validateResourceURL hooks (e.g. OpenCode), so the answer also determines what they should do.

What did you expect?

No response

Code to reproduce

SDK version

No response

Area

Auth

Langage dominant
TypeScript
Étoiles
13.8k
Forks
2.5k
Merge moyen
6 j 23 h
PR mergées (30 j)
2

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/typescript-sdk

Toutes les issues de modelcontextprotocol/typescript-sdk

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.