fix(mcp): strip trailing slash from OAuth resource parameter#14001
Open
venkat22022202 wants to merge 2 commits intovercel:mainfrom
Open
fix(mcp): strip trailing slash from OAuth resource parameter#14001venkat22022202 wants to merge 2 commits intovercel:mainfrom
venkat22022202 wants to merge 2 commits intovercel:mainfrom
Conversation
`new URL("https://mcp.example.com").href` returns
"https://mcp.example.com/" per the URL spec. Auth servers that do
exact matching on the resource parameter reject the request because
the trailing slash makes it a different URI than what was registered.
The MCP spec recommends the form without trailing slash:
https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#canonical-server-uri
Fix: strip trailing slash from `resource.href` in all three locations
where it's used as an OAuth parameter (startAuthorization,
exchangeAuthorization, refreshAuthorization).
Fixes vercel#13988
1 task
Address review feedback: the blanket regex would strip trailing slashes from path-based resource URIs like https://host/api/ which may be intentional. Extract canonicalResourceUri() helper that only strips the trailing slash when pathname is exactly "/" (origin-only URL). Path-based resource URIs are left unchanged.
Author
|
Good catch — fixed in 8206bfa. Extracted a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13988
new URL("https://mcp.example.com").hrefreturns"https://mcp.example.com/"per the URL spec. Auth servers that do exact matching on theresourceparameter reject the request because the trailing slash makes it a different URI than what was registered.Fix
Strip trailing slash from
resource.hrefin all three locations where it's used as an OAuth parameter:startAuthorization(line 454)exchangeAuthorization(line 678)refreshAuthorization(line 765)Why this is correct
The MCP spec explicitly recommends the form without trailing slash for better interoperability:
Source: https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#canonical-server-uri
Test plan
https://mcp.example.com) should no longer get rejected by auth servers doing exact matchhttps://mcp.example.com/api) are unaffected (no trailing slash to strip)