Repository navigation
fix(client): accept a protected resource that differs only by a trailing slash - #3042
AmineBenzaazaa wants to merge 1 commit into
Conversation
…ing slash checkResourceAllowed returned false early when the requested path was shorter than the configured one, so a server at https://host/mcp whose protected resource metadata advertises https://host/mcp/ failed auth(), while the reverse case passed. The prefix check below already normalises both paths to a trailing slash, so drop the early return. Fixes modelcontextprotocol#3041 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 91cf8df The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
koriyoshi2041
left a comment
There was a problem hiding this comment.
Reviewed 91cf8dff against the resource/path boundary. The focused auth-utils suite plus an independent matrix passed (25/25 total): both trailing-slash directions and a child path are accepted, while /mcp123, /mc, the parent path, and scheme/host/port changes remain rejected. I also checked the existing query/fragment behavior stayed unchanged.
core-internal typecheck, changed-file Prettier, and diff hygiene pass. I don't see the two-line change widening access beyond the intended path boundary.
|
The asymmetry is real: on main |
Motivation and Context
checkResourceAllowedreturnedfalseearly when the requested path was shorter than the configured one. A client pointed athttps://host/mcptherefore failedauth()against a server whose protected resource metadata advertiseshttps://host/mcp/, while the reverse case passed. The prefix check right below already normalises both paths to a trailing slash, so the early return was only adding the asymmetry.Fixes #3041
What changed
packages/core-internal/src/shared/authUtils.ts: removed the length early-return and noted in the doc comment that a single trailing slash is not significant.packages/core-internal/test/shared/authUtils.test.ts: the trailing-slash test now expects a match in both directions. A new test checks that a shorter, different path is still rejected (/foldervs/folder/sub/,/vs/mcp/,/mcvs/mcp/).How Has This Been Tested?
The updated test fails on
main(expected false to be true) and passes with the change.core-internal(1526 tests) andclient(998 tests) pass, andtypecheckandlintare clean.Breaking Changes
None. Only previously rejected
/xvs/x/pairs are now accepted; origin and path-prefix checks are unchanged.Types of changes
🤖 Generated with Claude Code