auth: RequireBearerToken omits error="invalid_token" when a presented token is rejected
Maintainer thường phản hồi trong vòng 1 ngày
@xianshujun đang làm issue này rồi.
Từ ngày 5/11/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- Go
- Star
- 5.3k
- Fork
- 607
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 82
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/go-sdk
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởneeds investigation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/go-sdk#745 · 13 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: whether MaxLineLength rejects a message depends on how the stream is readCó thể đã có người làm @Tangerg đã nhận hôm nay. Đang mở
modelcontextprotocol/go-sdk#1509 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
modelcontextprotocol/go-sdk#1506 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: closing a session right after a cancelled call drops notifications/cancelled, so the server handler keeps runningCó thể đã có người làm @vshalpnjabi đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
modelcontextprotocol/go-sdk#1505 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: a canceled write on IOTransport/StdioTransport cannot leave the write queueCó thể đã có người làm @Tangerg đã nhận 1 ngày trước. Đang mở
modelcontextprotocol/go-sdk#1498 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/go-sdk
Issue tương tự
-
[v3] KeyBindingManager calls (Add/Remove) are not converted into a case-insensitive accelerator.KeyĐang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
runtime: usleep sleeps nanoseconds instead of microseconds on linux/mips and linux/mips64Có thể đã có người làm @BRobertson7 đã nhận hôm nay. Đang mởcompiler/runtime
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
golang/go#82913 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws/aws-sdk-go-v2#3625 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
adrianbrad/queue#92 ·