Skip to content

fix(client): accept a protected resource that differs only by a trailing slash - #3042

Open
AmineBenzaazaa wants to merge 1 commit into
modelcontextprotocol:mainfrom
AmineBenzaazaa:fix/3041-resource-trailing-slash
Open

AmineBenzaazaa wants to merge 1 commit into
modelcontextprotocol:mainfrom
AmineBenzaazaa:fix/3041-resource-trailing-slash

Conversation

@AmineBenzaazaa

Copy link
Copy Markdown

Motivation and Context

checkResourceAllowed returned false early when the requested path was shorter than the configured one. A client pointed at https://host/mcp therefore failed auth() against a server whose protected resource metadata advertises https://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 (/folder vs /folder/sub/, / vs /mcp/, /mc vs /mcp/).
  • Changeset (patch: client).

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) and client (998 tests) pass, and typecheck and lint are clean.

Breaking Changes

None. Only previously rejected /x vs /x/ pairs are now accepted; origin and path-prefix checks are unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

🤖 Generated with Claude Code

…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>
@AmineBenzaazaa
AmineBenzaazaa requested a review from a team as a code owner October 16, 2026 22:01
@changeset-bot

changeset-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 91cf8df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/core-internal Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3042

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3042

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3042

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3042

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3042

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3042

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3042

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3042

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3042

commit: 91cf8df

This branch has not been deployed

No deployments
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.

checkResourceAllowed rejects a protected resource that differs from the server URL only by a trailing slash (one direction only)

1 participant