Scope-challenge middleware fails open when the token-scope fetch returns an error
維護者通常 3 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 78/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- go
研究方向
從兩個已命名的錯誤分支開始:pkg/http/middleware/scope_challenge.go 第 87-91 行附近,以及 pkg/http/handler.go 第 488-491 行附近。閱讀現有的 middleware 測試和 scope-fetcher 介面,以便一個回傳錯誤的 fake fetcher 能驅動這條鏈,正如重現草圖所示。完成意味著有一個測試證明 fetch 錯誤不再呼叫 next.ServeHTTP(改為 challenge 或 503),並且當無法取得 scopes 時,PAT inventory 路徑會扣留受 scope 門控的工具。
由索引模型根據 Issue 內容生成。
描述
Scope-challenge middleware fails open when the token-scope fetch returns an error
Target repository:
github/github-mcp-server
Affected revision:e3809fe91c75(the same branches are present onmainas of 2026-11-01).
Summary
Two error branches treat a failed token-scope lookup as "allow":
- OAuth
tools/callmiddleware —pkg/http/middleware/scope_challenge.go:87-91:
fetchedScopes, err := scopeFetcher.FetchTokenScopes(ctx, tokenInfo.Token)
if err != nil {
next.ServeHTTP(w, r)
return
}
When the scope endpoint is unavailable, the request is forwarded without the 403 + WWW-Authenticate: ... insufficient_scope challenge that the middleware exists to produce.
- PAT inventory filtering —
pkg/http/handler.go:488-491:
scopes, err := f.fetchScopes(ctx, token)
if err != nil {
return b
}
A failed scope fetch returns the unfiltered tool inventory instead of withholding tools whose scopes cannot be verified.
Reproduction
The real middleware chain can be driven with a fake scope fetcher:
fetcher := &fakeFetcher{err: errors.New("scope endpoint unavailable (simulated HTTP 503)")}
h := WithMCPParse()(WithScopeChallenge(&oauth.Config{}, fetcher)(recordingNext))
// tool scope map: delete_repository requires delete_repo + repo
// request: tools/call delete_repository, OAuth token, no scopes in context
Observed:
| Case | Result |
|---|---|
| fetch error | next=true, status=200, WWW-Authenticate="", no scopes installed in context |
fetched scopes [repo] (control) |
403, WWW-Authenticate: ... scope="delete_repo repo", next not called |
scopes [repo] already in context + erroring fetcher |
403 (fetcher not called) |
For the PAT path, with a real github.LabelWrite tool and a failing fetch, the production NewDefaultInventoryFactory exposed 134 tools including label_write, versus 46 tools when scopes were [gist] — 88 scope-gated tools exposed.
Expected behavior
If the token's scopes cannot be verified, the request should fail closed:
- the OAuth
tools/callmiddleware should return the insufficient-scope challenge (or a 503/authorization error), not call the next handler; - the PAT inventory path should withhold scope-gated tools, or fail the listing, rather than returning the unfiltered inventory.
A scope-endpoint outage is an authorization-verification failure, not evidence that the token is authorized.
Actual behavior
Both paths call the success path on error:
scope_challenge.go:88-91callsnext.ServeHTTP(w, r); the request reaches the tool handler withstatus=200, noWWW-Authenticate, and no scopes in context.handler.go:488-491returns the builder unchanged; with a failing fetch the production inventory exposed 134 tools (includinglabel_write) versus 46 tools when the token's scopes were[gist].
Impact
- Protocol/UX fail-open: the client is never told to re-authenticate and the call proceeds to GitHub. GitHub enforces the token's real scopes at the API, and the tool handlers use the caller's own token, so this does not widen privileges; an out-of-scope call still fails at the API.
- Inventory disclosure: a failing scope fetch reveals the names/descriptions of tools the token should not see. Those descriptions are public in this open-source repository, so the confidentiality impact is low.
- Severity: informational/low. The bug is that an availability failure silently disables a security control instead of failing closed or using a cached scope set.
Suggested fix
Fail closed on a scope-fetch error:
if err != nil {
http.Error(w, "scope verification unavailable", http.StatusServiceUnavailable)
return
}
or fall back to the last successfully fetched scopes for that token, never to the unrestricted path. For the inventory path, withhold scope-gated tools when scopes cannot be fetched.
Evidence
- PoC tests:
zz_verify173_test.go,zz_verify174_test.go(inside the target tree during the audit) - Upstream status checked on 2026-11-01: both error branches are still present.
Reproduced with the real go test runs (exit 0).
- 主要語言
- Go
- 星號
- 34.8k
- 分支
- 5.4k
- 平均合併
- 3 天 22 小時
- 30 天內合併 PR
- 31
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/github-mcp-server 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
github/github-mcp-server#3960 ·
維護者通常 3 天內回覆
-
ListLabelsOutput drops every label id from the typed response可能已有人在做 @Shanmukh-l33t 於 3 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 88/100
github/github-mcp-server#3923 · 1 個 reaction ·
維護者通常 3 天內回覆
-
create_or_update_file rejects explicitly empty file content可能已有人在做 @Elon-Jiang 於 8 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
github/github-mcp-server#3883 ·
維護者通常 3 天內回覆
-
csv_output silently overwrites distinct fields when flattened keys collide可能已有人在做 @Mystery01092000 於 9 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
github/github-mcp-server#3865 ·
維護者通常 3 天內回覆
-
update_issue_labels is annotated destructiveHint: false but replaces (removes) existing labels可能已有人在做 @shhhhhhjokerist 於 16 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 69/100
github/github-mcp-server#3760 · 2 則留言 ·
維護者通常 3 天內回覆
查看 github/github-mcp-server 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
JuliusBrussee/caveman#1594 ·
維護者通常 1 天內回覆
-
C-bug O-community X-blathers-triaged
難度 2/5 1-3 小時 新手友好度 66/100
cockroachdb/cockroach#176264 · 1 則留言 ·
-
security trivy
難度 2/5 1-3 小時 新手友好度 67/100
kubefleet-dev/kubefleet#1068 ·
維護者通常 3 天內回覆