Scope-challenge middleware fails open when the token-scope fetch returns an error
Les mainteneurs répondent en général sous 3 jours
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 78/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- go
- Domaine
- authorization, security
Piste de recherche
Commence par les deux branches d'erreur nommées : pkg/http/middleware/scope_challenge.go autour des lignes 87-91 et pkg/http/handler.go autour des lignes 488-491. Lis les tests middleware existants et l'interface du scope-fetcher pour qu'un faux fetcher renvoyant une erreur puisse piloter la chaîne, comme le montre le croquis de reproduction. Terminé signifie un test prouvant qu'une erreur de fetch n'appelle plus next.ServeHTTP (challenge ou 503 à la place), et que le chemin d'inventaire PAT retient les outils soumis au scope lorsque les scopes ne peuvent pas être récupérés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
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 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).
- Langage dominant
- Go
- Étoiles
- 34.8k
- Forks
- 5.4k
- Merge moyen
- 3 j 22 h
- PR mergées (30 j)
- 31
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de github/github-mcp-server
-
list_issues and search_issues: inconsistent `fields` allow-lists (`html_url` rejected by list)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
github/github-mcp-server#3960 ·
Les mainteneurs répondent en général sous 3 jours
-
ListLabelsOutput drops every label id from the typed responsePeut-être pris @Shanmukh-l33t l’a pris il y a 3 jours. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
github/github-mcp-server#3923 · 1 réaction ·
Les mainteneurs répondent en général sous 3 jours
-
create_or_update_file rejects explicitly empty file contentPeut-être pris @Elon-Jiang l’a pris il y a 8 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
github/github-mcp-server#3883 ·
Les mainteneurs répondent en général sous 3 jours
-
csv_output silently overwrites distinct fields when flattened keys collidePeut-être pris @Mystery01092000 l’a pris il y a 9 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
github/github-mcp-server#3865 ·
Les mainteneurs répondent en général sous 3 jours
-
update_issue_labels is annotated destructiveHint: false but replaces (removes) existing labelsPeut-être pris @shhhhhhjokerist l’a pris il y a 16 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 69/100
github/github-mcp-server#3760 · 2 commentaires ·
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de github/github-mcp-server
Issues similaires
-
test_archive_is_downloaded_after_logout_login doesn't wait for the storage client after loginOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
JuliusBrussee/caveman#1594 ·
Les mainteneurs répondent en général sous 1 jour
-
C-bug O-community X-blathers-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
cockroachdb/cockroach#176264 · 1 commentaire ·
-
security trivy
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
kubefleet-dev/kubefleet#1068 ·
Les mainteneurs répondent en général sous 3 jours