Skills URI validation accepts traversal segments in dynamic skill/directory URIs and trailing '?' / '#' delimiters
维护者通常 1 天内回复
@visy-ani 已经在做这个了。
开始于 2026年11月22日。
评估
调研方向
阅读 src/mcp/shared/skills.py 中 Skill._check_conformance 附近(第 127-128 行)、skill_name_from_uri(221-243)、parse_directory_uri(263-275)、_validate_resource_uri_in_skill 和 validate_directory_result;针对 resources == "dynamic" 的提前返回就是那里跳过校验的原因。查看相关的 #3685,了解百分号编码的 dot-segment 是如何处理的,以便两个修复保持一致。用 issue 中的代码片段复现,然后让列出的每个 URI 抛出 ValueError/ValidationError,并在现有 skills URI 测试旁边添加回归测试;完成意味着该代码片段会抛出,且测试通过。
由索引模型根据 Issue 内容生成。
描述
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
In src/mcp/shared/skills.py, there are two validation gaps in skill and directory URI checks (distinct from #3685, which covers percent-encoded dot-segments in child URIs inside _validate_resource_uri_in_skill / validate_directory_result):
-
Dot-segment traversal accepted in skill root URIs (when
resources="dynamic") and directory URIs:skill_name_from_uri()(lines 221-243) andparse_directory_uri()(lines 263-275) never check path segments for.or...- In
Skill._check_conformance()(lines 127-128),if self.resources == "dynamic": return selfreturns early before_validate_resource_uri_in_skill()ever runs, so a dynamicSkillwithuri="skill://org/../my-skill/SKILL.md"is accepted without error. - Similarly,
parse_directory_uri("skill://org/../../etc")(used bySkills._handle_read_directoryto gate incomingresources/directory/readrequests) accepts..segments.
-
Empty
?/#delimiters bypass query/fragment rejection:skill_name_from_uri(),_validate_resource_uri_in_skill(),parse_directory_uri(), andvalidate_directory_result()checkif not parts.scheme or parts.query or parts.fragment:.- Because
urllib.parse.urlsplit()returns empty strings ("") for a bare trailing?or#, URIs such asskill://my-skill/SKILL.md?,skill://my-skill/SKILL.md#,skill://my-skill?, andskill://my-skill#pass validation.
Example Code
from mcp.shared.skills import Skill, parse_directory_uri, skill_name_from_uri
# 1. Dynamic skill accepts '..' traversal segments in its own URI
skill = Skill(
uri="skill://org/../my-skill/SKILL.md",
frontmatter={"name": "my-skill", "description": "example"},
resources="dynamic",
)
print("1. Dynamic skill accepted:", skill.uri)
# 2. parse_directory_uri accepts '..' traversal segments
print("2. parse_directory_uri accepted:", parse_directory_uri("skill://org/../../etc"))
# 3. Empty '?' / '#' delimiters bypass query/fragment checks
for uri in ("skill://my-skill/SKILL.md?", "skill://my-skill/SKILL.md#"):
print(f"3a. skill_name_from_uri({uri!r}) ->", skill_name_from_uri(uri))
for uri in ("skill://my-skill?", "skill://my-skill#"):
print(f"3b. parse_directory_uri({uri!r}) ->", parse_directory_uri(uri))
Observed output:
1. Dynamic skill accepted: skill://org/../my-skill/SKILL.md
2. parse_directory_uri accepted: ('skill', 'org', '/../../etc')
3a. skill_name_from_uri('skill://my-skill/SKILL.md?') -> my-skill
3a. skill_name_from_uri('skill://my-skill/SKILL.md#') -> my-skill
3b. parse_directory_uri('skill://my-skill?') -> ('skill', 'my-skill', '')
3b. parse_directory_uri('skill://my-skill#') -> ('skill', 'my-skill', '')
Expected behavior: all of the above URIs should raise ValueError (and ValidationError on Skill), rejecting dot-segments (literal or percent-encoded, aligning with #3685) and any ? or # delimiter in the URI string.
I would be happy to submit a PR with regression tests if assigned.
Python & MCP Python SDK
- Python: 3.14.8
- mcp: 2.3.1.dev20+77001c96 (main @ 77001c96)
AI disclosure: AI assistance was used to help investigate and draft this issue; the reproduction and observed output were verified locally.
- 主要语言
- Python
- 星标
- 25k
- 派生
- 4.2k
- 平均合并
- 10 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/python-sdk 的其他 Issue
-
v2
难度 1/5 1 小时以内 新手友好度 86/100
modelcontextprotocol/python-sdk#3978 · 2 条评论 ·
维护者通常 1 天内回复
-
Client serves cached tools after its context exits with an exception可能已有人在做 @jonxsong 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
modelcontextprotocol/python-sdk#3968 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
modelcontextprotocol/python-sdk#3957 ·
维护者通常 1 天内回复
-
v2
难度 1/5 1 小时以内 新手友好度 91/100
modelcontextprotocol/python-sdk#3934 · 2 条评论 ·
维护者通常 1 天内回复
-
bug v1
难度 2/5 1-3 小时 新手友好度 79/100
modelcontextprotocol/python-sdk#3929 · 2 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
auto-reported bug
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
backend bug
难度 2/5 1-3 小时 新手友好度 86/100
nolte/kamerplanter#3193 ·
维护者通常 1 天内回复
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwise可能已有人在做 @abdulwaarith0 今天认领。 未关闭needs-triage
难度 2/5 1-3 小时 新手友好度 84/100
MakazhanAlpamys/Soup#3690 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复