auth: OAuth client rejects protected resource metadata when the MCP server URL has a query string

Đang mở
#1,519 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@beiryu đang làm issue này rồi.

Từ ngày 12/11/2026.

  • #1525 của @beiryu — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api, authentication

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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: checkResourceAllowed compares origin and path only.
  • Python: check_resource_allowed does the same, and uses the metadata's resource.
  • Rust: is_resource_identifier_valid notes "Query parameters may carry transport hints rather than resource identity."

Additional context

  • go-sdk v1.8.0; main has the same code (oauthex/resource_meta.go, auth/authorization_code.go).
  • protectedResourceMetadataURLs copies the URL with its query too, so the well-known candidates it builds also carry the query.
Ngôn ngữ chính
Go
Star
5.3k
Fork
614
Merge trung bình
23 giờ 55 phút
Pull request đã merge (30 ngày)
62

Chuẩn bị môi trường

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/go-sdk

Tất cả issue của modelcontextprotocol/go-sdk

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.