Title: Scope-challenge middleware fails open when the token-scope fetch returns an error · Issue #3929 · github/github-mcp-server · GitHub
Open Graph Title: Scope-challenge middleware fails open when the token-scope fetch returns an error · Issue #3929 · github/github-mcp-server
X Title: Scope-challenge middleware fails open when the token-scope fetch returns an error · Issue #3929 · github/github-mcp-server
Description: 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 on main as of 2026-11-01). Summary Two error bra...
Open Graph Description: 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 on main ...
X Description: 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 on main ...
Opengraph URL: https://github.com/github/github-mcp-server/issues/3929
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Scope-challenge middleware fails open when the token-scope fetch returns an error","articleBody":"# Scope-challenge middleware fails open when the token-scope fetch returns an error\r\n\r\n> Target repository: `github/github-mcp-server`\r\n> Affected revision: `e3809fe91c75` (the same branches are present on `main` as of 2026-11-01).\r\n\r\n## Summary\r\n\r\nTwo error branches treat a failed token-scope lookup as \"allow\":\r\n\r\n1. **OAuth `tools/call` middleware** — `pkg/http/middleware/scope_challenge.go:87-91`:\r\n\r\n```go\r\nfetchedScopes, err := scopeFetcher.FetchTokenScopes(ctx, tokenInfo.Token)\r\nif err != nil {\r\n next.ServeHTTP(w, r)\r\n return\r\n}\r\n```\r\n\r\nWhen the scope endpoint is unavailable, the request is forwarded **without** the `403` + `WWW-Authenticate: ... insufficient_scope` challenge that the middleware exists to produce.\r\n\r\n2. **PAT inventory filtering** — `pkg/http/handler.go:488-491`:\r\n\r\n```go\r\nscopes, err := f.fetchScopes(ctx, token)\r\nif err != nil {\r\n return b\r\n}\r\n```\r\n\r\nA failed scope fetch returns the unfiltered tool inventory instead of withholding tools whose scopes cannot be verified.\r\n\r\n## Reproduction\r\n\r\nThe real middleware chain can be driven with a fake scope fetcher:\r\n\r\n```go\r\nfetcher := &fakeFetcher{err: errors.New(\"scope endpoint unavailable (simulated HTTP 503)\")}\r\nh := WithMCPParse()(WithScopeChallenge(&oauth.Config{}, fetcher)(recordingNext))\r\n// tool scope map: delete_repository requires delete_repo + repo\r\n// request: tools/call delete_repository, OAuth token, no scopes in context\r\n```\r\n\r\nObserved:\r\n\r\n| Case | Result |\r\n|---|---|\r\n| fetch error | `next=true, status=200, WWW-Authenticate=\"\"`, no scopes installed in context |\r\n| fetched scopes `[repo]` (control) | `403`, `WWW-Authenticate: ... scope=\"delete_repo repo\"`, next not called |\r\n| scopes `[repo]` already in context + erroring fetcher | 403 (fetcher not called) |\r\n\r\nFor 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.\r\n\r\n## Expected behavior\r\n\r\nIf the token's scopes cannot be verified, the request should fail closed:\r\n\r\n- the OAuth `tools/call` middleware should return the insufficient-scope challenge (or a 503/authorization error), not call the next handler;\r\n- the PAT inventory path should withhold scope-gated tools, or fail the listing, rather than returning the unfiltered inventory.\r\n\r\nA scope-endpoint outage is an authorization-verification failure, not evidence that the token is authorized.\r\n\r\n## Actual behavior\r\n\r\nBoth paths call the success path on error:\r\n\r\n- `scope_challenge.go:88-91` calls `next.ServeHTTP(w, r)`; the request reaches the tool handler with `status=200`, no `WWW-Authenticate`, and no scopes in context.\r\n- `handler.go:488-491` returns the builder unchanged; with a failing fetch the production inventory exposed 134 tools (including `label_write`) versus 46 tools when the token's scopes were `[gist]`.\r\n\r\n## Impact\r\n\r\n* **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.\r\n* **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.\r\n* 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.\r\n\r\n## Suggested fix\r\n\r\nFail closed on a scope-fetch error:\r\n\r\n```go\r\nif err != nil {\r\n http.Error(w, \"scope verification unavailable\", http.StatusServiceUnavailable)\r\n return\r\n}\r\n```\r\n\r\nor 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.\r\n\r\n## Evidence\r\n\r\n- PoC tests: `zz_verify173_test.go`, `zz_verify174_test.go` (inside the target tree during the audit)\r\n- Upstream status checked on 2026-11-01: both error branches are still present.\r\n\r\nReproduced with the real `go test` runs (exit 0).\r\n","author":{"url":"https://github.com/soarkit","@type":"Person","name":"soarkit"},"datePublished":"2026-11-23T04:23:45Z","url":"https://github.com/github/github-mcp-server/issues/3929"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:21e77a51-973b-aba1-3b40-6ca14473aafd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF16:2E4E6F:5CC0B7:7C0C2D:6B0626B3 |
| html-safe-nonce | 6f6a55c835c5811eb77d6d79e607b4403c446cb7fde023e5ba54c0ea16aa44f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjE2OjJFNEU2Rjo1Q0MwQjc6N0MwQzJEOjZCMDYyNkIzIiwidmlzaXRvcl9pZCI6IjI2OTc1MzY3Nzg0OTk2NjM1MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a7443bbe27682a2c47ce18fec45b8d83830d450a49b73d3a5388daab3f7a3c45 |
| hovercard-subject-tag | issue:6552230467 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/github-mcp-server/3929/issue_layout |
| twitter:image | https://opengraph.githubassets.com/59b6e31d93c5ba915f993a2a7b1a2961a4979ef7b508e7679a2af6fd9ec13826/github/github-mcp-server/issues/3929 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/59b6e31d93c5ba915f993a2a7b1a2961a4979ef7b508e7679a2af6fd9ec13826/github/github-mcp-server/issues/3929 |
| og:image:alt | 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 on main ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | soarkit |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9e10bb0ecc0bd0f8692aa89586ee9b54e498d7ab9f244a44cdb5b93653a125ce |
| turbo-cache-control | no-preview |
| go-import | github.com/github/github-mcp-server git https://github.com/github/github-mcp-server.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 942771284 |
| octolytics-dimension-repository_nwo | github/github-mcp-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 942771284 |
| octolytics-dimension-repository_network_root_nwo | github/github-mcp-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32e57d5cc2ce6ce92ec6dceb65858344750c27c2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width