Skip to content

fix(server-legacy): use constant-time compare for OAuth client_secret - #2781

Open
Rahul-s-007 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Rahul-s-007:fix-oauth-client-secret-constant-time-compare
Open

fix(server-legacy): use constant-time compare for OAuth client_secret#2781
Rahul-s-007 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Rahul-s-007:fix-oauth-client-secret-constant-time-compare

Conversation

@Rahul-s-007

Copy link
Copy Markdown

Closes #2780

What

authenticateClient compared the client-supplied client_secret against the stored one with plain !==. Swapped to crypto.timingSafeEqual (with an explicit length check up front, since timingSafeEqual throws on unequal-length buffers rather than returning false).

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.ts explicitly uses SubtleCrypto.verify for its own HMAC check specifically because it's constant-time by spec. This brings clientAuth.ts in line with that same standard.

Testing

  • Added a test covering the timingSafeEqual length-mismatch path specifically (a different-length wrong secret), since that's the one edge case the naive !== version didn't need to handle.
  • All existing clientAuth tests continue to pass unchanged.
  • pnpm --filter @modelcontextprotocol/server-legacy test — 169/169 passed.
  • pnpm --filter @modelcontextprotocol/server-legacy lint / typecheck — clean.
  • Pre-push hook (build + typecheck + lint across the monorepo) passed.

Small, focused, single-file change plus its test — should be a quick review.

🤖 Generated with Claude Code

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>
@Rahul-s-007
Rahul-s-007 requested a review from a team as a code owner September 10, 2026 16:11
@changeset-bot

changeset-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 962ef38

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2781

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2781

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2781

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2781

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2781

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2781

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2781

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2781

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2781

commit: 962ef38

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.

OAuth client_secret comparison in clientAuth.ts is not constant-time

1 participant