modelcontextprotocol / modelcontextprotocol/python-sdk

DNS rebinding :* allowlist matches Host/Origin suffixes that are not ports

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

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

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

説明

What happened

TransportSecurityMiddleware treats allowed_hosts / allowed_origins entries that end in :* as a prefix match: value.startswith(base + ":").

With allowed_hosts=["127.0.0.1:*"] or ["wild.example:*"], these Host values are accepted today:

  • 127.0.0.1:8080.evil
  • wild.example:9000.evil

The same pattern accepts Origin http://wild.example:9000.evil for http://wild.example:*.

Existing tests only cover a numeric port (wild.example:9000). They do not cover a suffix after the port.

What I expected

base:* should mean base plus a numeric port, not any string that starts with base:.

How to reproduce

On main @ 08a3bc8:

from mcp.server.transport_security import TransportSecurityMiddleware, TransportSecuritySettings
from starlette.requests import Request

settings = TransportSecuritySettings(
    enable_dns_rebinding_protection=True,
    allowed_hosts=["wild.example:*"],
    allowed_origins=["http://wild.example:*"],
)
mw = TransportSecurityMiddleware(settings)
req = Request({"type": "http", "method": "GET", "headers": [(b"host", b"wild.example:9000.evil")]})
# validate_request returns None (accept). I expected 421.

I can send a PR that requires the suffix after base: to be digits, plus tests for the suffix cases. Happy to do that if you want it.

Written with AI assistance. I read the matcher next to tests/server/test_transport_security.py and reproduced it locally.

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

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

はじめの一歩

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

調査の方向性

mcp/server/transport_security.py から始めます。ここでは TransportSecurityMiddleware が allowed_hosts と allowed_origins を照合しています。次に tests/server/test_transport_security.py を読みます。報告されたサフィックスのケースを再現し、既存の数値ポートのカバレッジと比較します。数値ポートが引き続き受け入れられ、wild.example:9000.evil のような値と一致する Origin が拒否されれば完了です。

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

評価

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

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

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