Skip to content

Add nonce support#769

Closed
Glitched wants to merge 2 commits intomodelcontextprotocol:mainfrom
Glitched:add-nonce-support
Closed

Add nonce support#769
Glitched wants to merge 2 commits intomodelcontextprotocol:mainfrom
Glitched:add-nonce-support

Conversation

@Glitched
Copy link
Copy Markdown

Adds nonce parameter support to OAuth/OIDC authorization flows to prevent replay attacks on ID tokens.

Motivation and Context

Supporting nonces are necessary for id_token flows to prevent replay attacks.

How Has This Been Tested?

Just jest / automated tests. The changes are relatively minor, though.

Breaking Changes

The return type of startAuthorization() now includes an optional nonce field.

Hypothetically, someone could have provided explicit types on the return value like this:
const result: { authorizationUrl: URL; codeVerifier: string } = await startAuthorization(...);
Which would now be a type error, but I don't see why anyone would have an explicit type annotation there.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Glitched added 2 commits July 14, 2025 13:24
- Add optional nonce parameter to client startAuthorization()
- Auto-generate nonce when scope includes 'openid'
- Pass nonce through server authorization handler
- Update AuthorizationParams type to include nonce
- Add comprehensive tests for nonce handling

This enables proper OpenID Connect security by preventing replay attacks
on ID tokens.
- Add afterEach to restore all mocks
- Remove unnecessary mockClear() calls
- Ensures tests are properly isolated
@ihrpr ihrpr added this to the auth milestone Jul 15, 2025
@pcarleton pcarleton self-assigned this Jul 15, 2025
@felixweinberger felixweinberger added the auth Issues and PRs related to Authentication / OAuth label Mar 23, 2026
@felixweinberger
Copy link
Copy Markdown
Contributor

Hi @Glitched apologies that this and your newer version #770 fell through the cracks. Opened a tracking issue #1734 to evaluate whether this is an SDK responsibility to validate or something that should be handled on the consumer side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth Issues and PRs related to Authentication / OAuth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants