fix(server-legacy): use constant-time compare for OAuth client_secret - #2781
Open
Rahul-s-007 wants to merge 1 commit into
Open
Conversation
authenticateClient compared client_secret with plain !==, which is a timing side channel (CWE-208) on a value meant to be secret. Swap to crypto.timingSafeEqual, matching the constant-time approach this repo already uses for its own HMAC verification in requestStateCodec.ts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Closes #2780
What
authenticateClientcompared the client-suppliedclient_secretagainst the stored one with plain!==. Swapped tocrypto.timingSafeEqual(with an explicit length check up front, sincetimingSafeEqualthrows on unequal-length buffers rather than returningfalse).Why
Plain string comparison short-circuits at the first mismatching character — a timing side channel (CWE-208) on a value meant to be secret. This repo already treats this class of bug as worth avoiding:
requestStateCodec.tsexplicitly usesSubtleCrypto.verifyfor its own HMAC check specifically because it's constant-time by spec. This bringsclientAuth.tsin line with that same standard.Testing
timingSafeEquallength-mismatch path specifically (a different-length wrong secret), since that's the one edge case the naive!==version didn't need to handle.clientAuthtests continue to pass unchanged.pnpm --filter @modelcontextprotocol/server-legacy test— 169/169 passed.pnpm --filter @modelcontextprotocol/server-legacy lint/typecheck— clean.Small, focused, single-file change plus its test — should be a quick review.
🤖 Generated with Claude Code