Skip to content

Bearer challenge points resource_metadata to a 404 when resourceUri has a path #207

Description

@mcollina

When authorization.resourceUri includes a path (for example https://mcp.example.com/mcp, which authorization.md lists as a valid canonical URI), protected-resource discovery breaks:

  • src/auth/prehandler.ts builds the 401 challenge as resource_metadata="${resourceUri}/.well-known/oauth-protected-resource". That gives https://mcp.example.com/mcp/.well-known/oauth-protected-resource, which returns 404.
  • src/routes/well-known.ts only serves /.well-known/oauth-protected-resource and /.well-known/oauth-protected-resource/mcp. The /mcp variant appends /mcp again and advertises resource: "https://mcp.example.com/mcp/mcp".

Expected (RFC 9728 §3.1): the metadata URL is the origin plus /.well-known/oauth-protected-resource plus the resource path, and the advertised resource equals resourceUri exactly.

Repro: configure resourceUri: 'https://mcp.example.com/mcp', send an unauthenticated request to /mcp, then fetch the URL in the resource_metadata parameter. The fetch returns 404.

Found while reviewing #170. Already present on main.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions