modelcontextprotocol / modelcontextprotocol/typescript-sdk
/token endpoint should validate redirect_uri matches
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
Describe the bug
The /token endpoint doesn't check that the redirect_uri provided in the request matches the redirect_uri originally provided in the /authorize request, which is required by https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3.
redirect_uri: REQUIRED, if the "redirect_uri" parameter was included in the authorization request as described in Section 4.1.1, and their values MUST be identical.
This seems like a problem with the way the AuthProvider interface is designed - the only method the provider can expose is challengeForAuthorizationCode, so there's no way for the provider to tell the SDK what redirect_uri was originally provided. Fixing this will require a change to the interface (and the cleanest way to fix it is a breaking change), so we should probably fix this before too many integrations grow around the existing AuthProvider interface.
To Reproduce
Steps to reproduce the behavior:
- Make an
/authorizerequest - Make an
/tokenrequest with a differentredirect_uri; this returns a successful response.
Expected behavior
The /token request should return an HTTP 400 with error=invalid_grant (https://datatracker.ietf.org/doc/html/rfc6749#section-5.2).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the AuthProvider interface and the /authorize and /token endpoint handlers. Trace how the redirect_uri from authorization is represented when the authorization code is created, then verify the token request can compare it and return HTTP 400 with invalid_grant on a mismatch. Add or update coverage for matching and different redirect_uri values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100