modelcontextprotocol / modelcontextprotocol/python-sdk

check_resource_allowed treats /api/../admin as under /api

Offen Anfängerfreundlich
#3,464 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

v1 v2
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

What happened

check_resource_allowed pads trailing slashes and then does requested_path.startswith(configured_path). It does not collapse . / ...

On main @ 08a3bc8 these return True:

  • requested https://example.com/api/../admin vs configured https://example.com/api
  • requested https://example.com/mcp/.. vs configured https://example.com/mcp
  • requested https://example.com/api/%2e%2e/admin vs configured https://example.com/api

tests/shared/test_auth_utils.py already rejects /api123 vs /api (path-boundary). Dot-segments are not covered.

What I expected

A requested path that walks out of the configured prefix should not match. /api/foo/../v1 vs /api can still match after normalisation, because it stays under /api.

How to reproduce

from mcp.shared.auth_utils import check_resource_allowed

check_resource_allowed("https://example.com/api/../admin", "https://example.com/api")
# True today. I expected False.

I can send a PR that percent-decodes once, runs posixpath.normpath, then keeps the existing trailing-slash prefix rule. Happy to do that if you want it.

Written with AI assistance. I read auth_utils.py next to the path-boundary tests and reproduced it locally.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in auth_utils.py bei check_resource_allowed und überprüfe die vorhandenen Fälle zu Pfadgrenzen in tests/shared/test_auth_utils.py. Füge Abdeckung für Punktsegmente, prozentkodierte Punktsegmente und Pfade hinzu, die unter dem konfigurierten Präfix bleiben, und führe anschließend die relevanten Auth-Utility-Tests aus. Erledigt ist die Aufgabe, wenn Pfade, die das konfigurierte Präfix verlassen, nicht übereinstimmen, während normalisierte Pfade, die darunter bleiben, weiterhin übereinstimmen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api, security
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
82/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.