| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Without normalization, ``check_resource_allowed`` accepts paths that contain
unresolved dot-segments or percent-encoded equivalents:
- ``/api/../admin`` passes ``startswith("/api/")`` although it resolves to ``/admin``
- ``/api/%2e%2e/admin`` does the same via URL-encoding
- ``/api//victim`` can synthesize a fake segment boundary
A downstream resource server that normalizes the path (i.e., any standard web
framework router) would resolve the request to a different scope than the one
the token was authorized for — a confused-deputy class issue.
Fix: decode percent-encoding (``unquote``) and resolve dot-segments
(``posixpath.normpath``) before the ``startswith`` hierarchical match. Trailing
slash handling is preserved.
Adds tests for dot-segment escape, percent-encoded escape, double-slash
collapse, and a self-reference dot-segment that should remain a valid match.
Single-line consolidation in test file (legitimate_paths_still_match docstring/body).
|
Thanks for the PR. Per our CONTRIBUTING.md we ask that PRs start from a linked, triaged issue with maintainer buy-in, which this one doesn't have yet. Closing as part of a general backlog cleanup following the v2 release. If this is still relevant against v2, feel free to reopen. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
check_resource_allowed in src/mcp/shared/auth_utils.py compares URL paths via startswith after only trailing-slash normalization. Paths that contain unresolved dot-segments or their percent-encoded equivalents can satisfy the prefix check while resolving to a path outside the configured scope on any downstream server that normalizes the URL — which is the standard behavior of every common web framework router.
Examples that pre-fix return True:
This is a confused-deputy class issue: the auth check passes against the literal-string prefix while the downstream router resolves the request to a different scope than the one the token was authorized for. While exploitability depends on whether the downstream resource server is configured with a smaller scope than the literal prefix the token presents, the defense-in-depth principle is to normalize before comparison.
The fix
_normalize_url_path decodes percent-encoding (unquote) and resolves dot-segments (posixpath.normpath) before the startswith comparison runs. Trailing-slash semantics are preserved so existing legitimate matches still work.
Test plan
Notes
AI-assisted.