Skip to content

fix(auth): normalize resource path dot-segments - #3308

Open
SarathChandraBellam wants to merge 2 commits into
modelcontextprotocol:mainfrom
SarathChandraBellam:fix/resource-path-normalization-3303
Open

fix(auth): normalize resource path dot-segments#3308
SarathChandraBellam wants to merge 2 commits into
modelcontextprotocol:mainfrom
SarathChandraBellam:fix/resource-path-normalization-3303

Conversation

@SarathChandraBellam

@SarathChandraBellam SarathChandraBellam commented Aug 14, 2026

Copy link
Copy Markdown

Summary

  • Resolve raw and percent-encoded dot-segments before checking resource hierarchy.
  • Preserve repeated path separators and encoded separators such as %2F.
  • Add regression tests for traversal and encoding cases.

Fixes #3303

Why

check_resource_allowed() previously used a direct startswith() comparison after only trailing-slash normalization. A requested resource such as /api/../admin could therefore pass a check configured for /api, even though it resolves outside the configured resource.

The implementation decodes only encoded dots (%2e), rather than fully unquoting the path. It then applies RFC-style dot-segment removal without collapsing empty path segments, so repeated separators remain significant. This avoids both path traversal and accidental widening of a resource boundary such as /api//.

Validation

  • pytest tests/shared/test_auth_utils.py -q — 19 passed
  • Full test suite — 5584 passed, 10 skipped, 1 xfailed
  • Coverage — 100.00%
  • Ruff check and format — passed
  • Pyright — passed
  • strict-no-cover — passed

AI assistance was used during investigation and implementation; I reviewed the resulting code and tests myself.

@SarathChandraBellam
SarathChandraBellam marked this pull request as ready for review August 14, 2026 07:25

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/mcp/shared/auth_utils.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check_resource_allowed(): path matching skips dot-segment/percent-encoding normalization (auth-boundary bypass)

2 participants