DNS rebinding :* allowlist matches Host/Origin suffixes that are not ports
还没有人认领这个 Issue。
评估
调研方向
从 mcp/server/transport_security.py 开始,其中 TransportSecurityMiddleware 会匹配 allowed_hosts 和 allowed_origins,然后阅读 tests/server/test_transport_security.py。复现报告中的后缀情况,并将其与现有的数字端口覆盖范围进行比较。完成的标准是数字端口仍然被接受,而像 wild.example:9000.evil 这样的值以及匹配的 Origin 会被拒绝。
由索引模型根据 Issue 内容生成。
描述
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.evilwild.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.
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/python-sdk 的其他 Issue
-
v1 v2
难度 2/5 1-3 小时 新手友好度 85/100
modelcontextprotocol/python-sdk#3546 · 4 条评论 ·
-
v1 v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3545 · 1 条评论 ·
-
v1 v2
难度 1/5 1 小时以内 新手友好度 91/100
modelcontextprotocol/python-sdk#3508 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
难度 2/5 1-3 小时 新手友好度 82/100
modelcontextprotocol/python-sdk#3492 · 1 条评论 ·
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
link-check link-check:sphinx-theme
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
难度 1/5 1 小时以内 新手友好度 90/100