Skip to content

fix(server): validate OAuth code redirect URI#1997

Open
Genmin wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
Genmin:fix/v1x-token-redirect-uri-validation
Open

fix(server): validate OAuth code redirect URI#1997
Genmin wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
Genmin:fix/v1x-token-redirect-uri-validation

Conversation

@Genmin
Copy link
Copy Markdown

@Genmin Genmin commented Apr 30, 2026

Summary

  • validate authorization-code token requests against the original authorization redirect_uri when providers expose it
  • add a provider hook for revoking tokens previously issued for a replayed authorization code
  • wire the demo in-memory OAuth provider to store redirect URIs and code-to-token mappings

Why

The v1.x OAuth token handler could exchange an authorization code with a different redirect_uri than the one used at /authorize. It also had no framework hook to let providers revoke tokens after authorization-code reuse was detected.

Fixes #209.
Fixes #235.

Validation

  • npm test -- test/server/auth/handlers/token.test.ts test/examples/server/demoInMemoryOAuthProvider.test.ts
  • npm run typecheck
  • npx eslint src/server/auth/provider.ts src/server/auth/handlers/token.ts src/examples/server/demoInMemoryOAuthProvider.ts test/server/auth/handlers/token.test.ts test/examples/server/demoInMemoryOAuthProvider.test.ts
  • npx prettier --check .changeset/fix-v1x-oauth-code-redirect.md src/server/auth/provider.ts src/server/auth/handlers/token.ts src/examples/server/demoInMemoryOAuthProvider.ts test/server/auth/handlers/token.test.ts test/examples/server/demoInMemoryOAuthProvider.test.ts
  • git diff --check

@Genmin Genmin requested review from a team as code owners April 30, 2026 16:26
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

🦋 Changeset detected

Latest commit: 90972ff

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

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
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@1997

commit: 90972ff

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.

1 participant