fetch: --allowed-hosts accepts wildcard IP entries (e.g. *.0.0.1) and matches any IPv4 ending with that suffix

未关闭 适合新手
#5,521 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend, security

调研方向

从 src/fetch/src/mcp_server_fetch/allowlist.py 开始,阅读 issue 指出的受影响入口 normalize_allowed_host 和 host_is_allowed。检查现有的允许主机规范化和匹配测试,然后补充对带通配符的 IP 字面量、数字后缀和 IP 地址主机的测试覆盖。完成标准是这些输入会被拒绝,或永远不会匹配 IP 字面量,同时主机名子域通配符仍能正常工作。

由索引模型根据 Issue 内容生成。

描述

Problem

mcp-server-fetch's --allowed-hosts allowlist (src/fetch/src/mcp_server_fetch/allowlist.py) documents two valid entry forms:

Two entry forms only, to keep the semantics obvious: an exact host (a name or an IP literal), and *.example.com, which matches any subdomain at any depth of example.com...

However, normalize_allowed_host only checks ipaddress.ip_address(...) when not wildcard (line 37). When a wildcard prefix *. is given before an IP literal or numeric IP suffix (such as *.10.0.0.1 or *.0.0.1), httpx.URL(f"http://{name}/") parses name without error and returns *.10.0.0.1 / *.0.0.1.

Then in host_is_allowed(host, allowed_hosts), host.endswith(entry[1:]) matches any IPv4 literal ending with .0.0.1 (for example, *.0.0.1 matches both 10.0.0.1 and 127.0.0.1).

from mcp_server_fetch.allowlist import host_is_allowed, normalize_allowed_hosts

entries = normalize_allowed_hosts(["*.0.0.1"])  # returns ('*.0.0.1',)
assert host_is_allowed("127.0.0.1", entries) is True
assert host_is_allowed("10.0.0.1", entries) is True

Expected

  • normalize_allowed_host rejects wildcard IP literals and numeric-TLD wildcard suffixes (*.10.0.0.1, *.0.0.1, *.[::1]) with ValueError.
  • host_is_allowed does not match *. subdomain wildcards against IP address literals.
主要语言
TypeScript
星标
91.9k
派生
11.9k
平均合并
3 小时 10 分钟
30 天内合并 PR
178

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/servers 的其他 Issue

查看 modelcontextprotocol/servers 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。