modelcontextprotocol / modelcontextprotocol/python-sdk
check_resource_allowed treats /api/../admin as under /api
まだ誰も着手していません。
- 主要言語
- 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/../adminvs configuredhttps://example.com/api - requested
https://example.com/mcp/..vs configuredhttps://example.com/mcp - requested
https://example.com/api/%2e%2e/adminvs configuredhttps://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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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