check_resource_allowed treats /api/../admin as under /api
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in auth_utils.py at check_resource_allowed and review the existing path-boundary cases in tests/shared/test_auth_utils.py. Add coverage for dot-segments, percent-encoded dot-segments, and paths that remain under the configured prefix, then run the relevant auth utility tests. Done means paths escaping the configured prefix do not match while normalized paths that stay under it still do.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 24.3k
- Forks
- 4k
- Avg merge
- 1d 19m
- Merged PRs (30d)
- 29
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/python-sdk
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelcontextprotocol/python-sdk#3546 · 5 comments ·
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelcontextprotocol/python-sdk#3545 · 1 comment ·
-
v1 v2
Difficulty 1/5 Under an hour Newbie friendliness 91/100
modelcontextprotocol/python-sdk#3508 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
modelcontextprotocol/python-sdk#3492 · 1 comment ·
All issues in modelcontextprotocol/python-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100