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.
What happened
check_resource_allowedpads trailing slashes and then doesrequested_path.startswith(configured_path). It does not collapse./...On
main@08a3bc8these returnTrue:https://example.com/api/../adminvs configuredhttps://example.com/apihttps://example.com/mcp/..vs configuredhttps://example.com/mcphttps://example.com/api/%2e%2e/adminvs configuredhttps://example.com/apitests/shared/test_auth_utils.pyalready rejects/api123vs/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/../v1vs/apican still match after normalisation, because it stays under/api.How to reproduce
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.pynext to the path-boundary tests and reproduced it locally.