modelcontextprotocol / modelcontextprotocol/python-sdk

check_resource_allowed treats /api/../admin as under /api

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

还没有人认领这个 Issue。

v1 v2
主要语言
Python
星标
24.3k
派生
4k
平均合并
1 天 1 小时
30 天内合并 PR
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/../admin vs configured https://example.com/api
  • requested https://example.com/mcp/.. vs configured https://example.com/mcp
  • requested https://example.com/api/%2e%2e/admin vs configured https://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.

贡献指南

打开贡献指南

从这里开始

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

把新 issue 发到你的邮箱

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