auth: OAuth client rejects protected resource metadata when the MCP server URL has a query string
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- go
- 领域
- api, authentication
调研方向
Start with oauthex/resource_meta.go and auth/authorization_code.go, which the issue identifies as containing the URL handling and strict resource comparison. Trace how query and fragment components reach metadata candidate URLs and the resource parameter, then check the OAuth metadata tests. Done when a server URL with a query or fragment matches metadata naming the same URL without those components, and the resource parameter uses that normalized URL.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
The OAuth client fails to authorize against an MCP server whose URL carries a query string, when the server's Protected Resource Metadata names the resource without that query.
AuthorizationCodeHandler passes req.URL.String(), query included, as the resource URL. oauthex.GetProtectedResourceMetadata then compares it to the metadata's resource with !=, so every candidate is refused and the handler falls back to treating the server root as the authorization server.
RFC 8707 section 2 says a resource indicator "SHOULD NOT include a query component", so a server that takes configuration in its URL (for example https://mcp.example.com/mcp?features=flags) publishes "resource": "https://mcp.example.com/mcp", and its WWW-Authenticate challenge points at metadata for that resource.
This is the same strict comparison as #886 (trailing slash), for the query component.
To Reproduce
func TestQueryInServerURL(t *testing.T) {
var base string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{
"resource": base + "/mcp",
"authorization_servers": []string{"https://as.example"},
})
}))
defer srv.Close()
base = srv.URL
meta := base + "/.well-known/oauth-protected-resource/mcp"
if _, err := oauthex.GetProtectedResourceMetadata(context.Background(), meta, base+"/mcp", srv.Client()); err != nil {
t.Fatal(err) // passes
}
if _, err := oauthex.GetProtectedResourceMetadata(context.Background(), meta, base+"/mcp?features=flags", srv.Client()); err != nil {
t.Fatal(err) // got metadata resource ".../mcp", want ".../mcp?features=flags"
}
}
Expected behavior
The server URL's query (and fragment) is dropped before the resource is compared and before it is sent as the resource parameter.
The other official SDKs accept this case:
- TypeScript:
checkResourceAllowedcompares origin and path only. - Python:
check_resource_alloweddoes the same, and uses the metadata's resource. - Rust:
is_resource_identifier_validnotes "Query parameters may carry transport hints rather than resource identity."
Additional context
- go-sdk v1.8.0;
mainhas the same code (oauthex/resource_meta.go,auth/authorization_code.go). protectedResourceMetadataURLscopies the URL with its query too, so the well-known candidates it builds also carry the query.
- 主要语言
- Go
- 星标
- 5.3k
- 派生
- 614
- 平均合并
- 23 小时 55 分钟
- 30 天内合并 PR
- 62
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/go-sdk 的其他 Issue
-
mcp: typed tool handlers lose wrapped JSON-RPC errors可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
modelcontextprotocol/go-sdk#1529 · 1 条评论 ·
维护者通常 1 天内回复
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions可能重新可做 关联的 PR 已关闭且未合并。 未关闭needs investigation
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/go-sdk#745 · 13 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
mcp: ClientSession.ReadResource keeps uncacheable and expired results until the session ends可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 74/100
modelcontextprotocol/go-sdk#1526 ·
维护者通常 1 天内回复
-
mcp: streamable client keeps the session ID from a rejected server/discover, so the fallback initialize fails可能已有人在做 @simon0191 于 1 天前认领。 未关闭
modelcontextprotocol/go-sdk#1522 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
`ping` and `logging/setLevel` still sent for protocol 2026-07-28可能已有人在做 @nahapetyan-serob 于 1 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
modelcontextprotocol/go-sdk#1518 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/go-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
-
evener-transcript-v2-upgrade tool still scans transcript files through bufio's 4 KiB default buffer未关闭
难度 1/5 1 小时以内 新手友好度 78/100
prime-radiant-inc/evener#6370 ·
维护者通常 1 天内回复
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOF未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Mend: dependency security vulnerability
难度 2/5 1-3 小时 新手友好度 65/100
-
Mend: dependency security vulnerability
难度 2/5 1-3 小时 新手友好度 62/100
ManageIQ/manageiq-pods#1476 ·
维护者通常 1 天内回复