OAuth discovery drops explicit default ports from advertised issuer identifiers

未关闭
#1,420 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@gocamille 已经在做这个了。

开始于 2026年10月31日。

评估

这个 Issue 还没有评估数据。

描述

bug P1 ready for work T-security T-transport

Summary

OAuth discovery rejects internally consistent metadata when the advertised authorization-server issuer contains an explicit default port, such as https://auth.example.com:443/tenant1.

The original identifier is parsed into a Url, which removes :443. The serialized URL is then used as the expected issuer, while AuthorizationMetadata.issuer retains the original JSON string.

Reproduced against main at c742b5536724ec376b14b7ddcbbd024b7d6ae163 (rmcp 3.8.0). The same code is present at 98a54789b80110ad210495c4ad845c89e1980471, the rmcp revision pinned by Codex 0.166.0.

Reproduction with simulated metadata

Using the existing RecordingOAuthHttpClient test helper, return these responses during AuthorizationManager::resolve_metadata():

  1. An initial 401 for the MCP resource https://mcp.example.com/.
  2. Protected resource metadata:
{
  "resource": "https://mcp.example.com/",
  "authorization_servers": ["https://auth.example.com:443/tenant1"]
}
  1. Authorization-server metadata:
{
  "issuer": "https://auth.example.com:443/tenant1",
  "authorization_endpoint": "https://auth.example.com/tenant1/authorize",
  "token_endpoint": "https://auth.example.com/tenant1/token"
}

No real OAuth credentials or external service are needed.

Expected: discovery accepts the metadata because its issuer exactly matches the identifier advertised by protected resource metadata.

Actual:

Authorization server issuer mismatch: expected https://auth.example.com/tenant1, received https://auth.example.com:443/tenant1

Root cause

In crates/rmcp/src/transport/auth.rs, authorization_metadata_from_resource_metadata() parses the candidate with Url::parse(candidate), then calls:

.try_discover_oauth_server(&candidate_url, Some(candidate_url.as_str()))

candidate_url.as_str() has already lost the explicit default port. Parsing is appropriate for transport, but its normalized output no longer represents the original OAuth identifier.

This also creates an asymmetric check: an advertised issuer containing :443 can incorrectly match metadata that omits it, because the expected value has been normalized first.

Relation to #1144 / #1145

#1145 preserves the issuer through discovery to address the trailing-slash problem in #1144, but retains the parsed URL representation. That preserves a tenant's trailing slash while still losing an explicit default port and host casing.

I did not find an existing issue specifically covering this default-port case. #1268 concerns HTTP Origin validation and is a separate problem.

Proposed approach

Preserve the advertised absolute issuer string for identity validation, separately from the parsed URL used to construct discovery requests. Keep the existing resolved-URL behavior for legacy relative references.

The fix should not normalize both issuers or treat identifiers with and without :443 as interchangeable. RFC 8414 sections 3.3 and 4 require validation against the original issuer identifier.

Local validation and question

A local candidate fix has mocked regression coverage for matching and mismatched default ports, nonstandard ports, host casing, tenant paths and trailing slashes, including the complete metadata discovery path. A before/after comparison of OAuth and HTTP tests found no new failures; full upstream CI has not been run.

Would preserving the original advertised identifier be an appropriate follow-up to #1145 before submitting a PR?

AI assistance was used for the investigation and local regression tests. All examples above use fictional domains and tenants.

主要语言
Rust
星标
4.1k
派生
694
平均合并
3 天 14 小时
30 天内合并 PR
39

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/rust-sdk 的其他 Issue

查看 modelcontextprotocol/rust-sdk 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。