modelcontextprotocol / modelcontextprotocol/python-sdk

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

オープン 初心者向け
#3,464 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

v1 v2
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

auth_utils.py の check_resource_allowed から始め、tests/shared/test_auth_utils.py にある既存のパス境界のケースを確認します。ドットセグメント、パーセントエンコードされたドットセグメント、および設定されたプレフィックス配下に留まるパスのカバレッジを追加し、その後、関連する auth utility テストを実行します。設定されたプレフィックスから抜けるパスが一致せず、その配下に留まる正規化されたパスは引き続き一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api, security
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
82/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。