check_resource_allowed treats /api/../admin as under /api
还没有人认领这个 Issue。
评估
调研方向
从 auth_utils.py 中的 check_resource_allowed 开始,检查 tests/shared/test_auth_utils.py 中现有的路径边界用例。为点段、百分号编码的点段以及仍位于已配置前缀下的路径添加覆盖,然后运行相关的 auth utility 测试。完成标准是:超出已配置前缀的路径不匹配,而仍位于其下的规范化路径仍然匹配。
由索引模型根据 Issue 内容生成。
描述
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/../adminvs configuredhttps://example.com/api - requested
https://example.com/mcp/..vs configuredhttps://example.com/mcp - requested
https://example.com/api/%2e%2e/adminvs configuredhttps://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.
- 主要语言
- 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