auth: RequireBearerToken omits error="invalid_token" when a presented token is rejected
维护者通常 1 天内回复
@xianshujun 已经在做这个了。
开始于 2026年11月5日。
评估
这个 Issue 还没有评估数据。
描述
Checklist
- I searched the existing issues, and this has not been reported before.
- This is a real problem that I ran into myself, using the latest release of the SDK.
- I ran into it in a production system, not in a toy example, a benchmark, or an automated or AI-driven scan of the code.
- I (a human) examined the relevant SDK code, and wrote or reviewed every line of this report. It is not unreviewed AI output.
- This report is brief and concise, and sticks to the facts needed to understand the problem.
What happened?
#1134 asked for both RFC 6750 §3.1 error codes in the WWW-Authenticate challenge: insufficient_scope on the 403, and invalid_token on the 401 for a rejected token. #1421 added only insufficient_scope, and #1135, which added both, was closed as a duplicate of #1134 (comment), so the invalid_token half was dropped.
On main, a presented token that the verifier rejects with ErrInvalidToken, or that has expired, still gets a 401 whose challenge is the same as for a request with no credentials:
WWW-Authenticate: Bearer resource_metadata="...", scope="..."
RFC 6750 §3.1 says this challenge should carry error="invalid_token", while §3 says a request with no credentials should carry no error code. With one header for both, a client cannot tell a rejected token from missing credentials.
How to reproduce
- Wrap a handler with
RequireBearerToken(verifier, &RequireBearerTokenOptions{ResourceMetadataURL: "https://example.com/.well-known/oauth-protected-resource", Scopes: []string{"read"}}), whereverifierreturnsErrInvalidToken. - Send a request with
Authorization: Bearer some-token. - The response is 401 with
WWW-Authenticate: Bearer resource_metadata="...", scope="read", the same header a request without anAuthorizationheader gets.
Expected: the challenge for the rejected token also carries error="invalid_token". The challenge for the request without credentials stays as it is.
Where did you hit this?
ThunderID's MCP server (https://github.com/thunder-id/thunderid) protects its /mcp endpoint with RequireBearerToken. We track the endpoint's RFC 6750 conformance in thunder-id/thunderid#4509.
Go MCP SDK version
v1.8.0. Also checked main at f91620f.
Go version
1.27.2
Logs
N/A
- 主要语言
- Go
- 星标
- 5.3k
- 派生
- 607
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 81
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/go-sdk 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/go-sdk#1512 ·
维护者通常 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 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
modelcontextprotocol/go-sdk#1506 · 2 条评论 ·
维护者通常 1 天内回复
-
mcp: closing a session right after a cancelled call drops notifications/cancelled, so the server handler keeps running可能已有人在做 @vshalpnjabi 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
modelcontextprotocol/go-sdk#1505 · 1 条评论 ·
维护者通常 1 天内回复
-
mcp: list_changed can only be broadcast; a server cannot notify one session (2026-07-28 subscriptions/listen)可能已有人在做 @nahapetyan-serob 于 1 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 32/100
modelcontextprotocol/go-sdk#1480 · 1 条评论 · 已指派 2 人 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/go-sdk 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
bug raised-by:verifier
难度 2/5 1-3 小时 新手友好度 76/100
medici-finance/assay#5697 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
sonatype-nexus-community/terraform-provider-sonatypeiq#101 ·
维护者通常 1 天内回复
-
area: metrics area: tracing contribfest enhancement good first issue
难度 2/5 1-3 小时 新手友好度 83/100
open-telemetry/opentelemetry-ebpf-instrumentation#4188 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
blinklabs-io/dingo#6074 ·
维护者通常 1 天内回复