client_secret_basic: applyBasicAuth base64-encodes raw credentials instead of form-encoding each half (RFC 6749 §2.3.1)

オープン
#3,263 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@gdut4140 がすでに取り組んでいます。

2026年10月16日 から。

  • #3039 @gdut4140 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
typescript

調査の方向性

Read packages/client/src/client/auth.ts at applyBasicAuth and the linked issue #3039, which already has an open pull request for this fix. The issue describes the credential encoding cases and expected behavior; compare the existing tests and pull request changes to see what remains to be done.

索引モデルが issue の本文から書いたものです。

説明

v1 v2

What's broken

applyBasicAuth (packages/client/src/client/auth.ts:880 on main) sends the client id and secret to the Authorization header without the per-half encoding that RFC 6749 §2.3.1 requires:

const credentials = btoa(`${clientId}:${clientSecret}`);
headers.set('Authorization', `Basic ${credentials}`);

§2.3.1 says the client must form-encode client_id and client_secret before joining them with :, and the token endpoint base64-decodes, splits on the first :, then form-decodes each half. Sending the raw values means the server recovers different credentials than the client intended:

client_id / client_secret sent server recovers problem
cid / a+b username cid, password `a b` + decodes as a space
client id / sec:ret+with=special username client, password id:sec:ret with=special : in the id splits at the wrong place, + turns into a space
cid / p€ss — btoa throws InvalidCharacterError before any request is sent
cid / 50%off — % alone is not valid form encoding; strict servers fail to decode

Only credentials made of unreserved characters are unaffected.

Repro

Any client_secret_basic flow with a secret containing +, %, =, /, a client id containing :, or a non-Latin-1 character. To see the server-side recovery without a live IdP:

// What the client sends today
const auth = `Basic ${Buffer.from('cid:a+b').toString('base64')}`;
const raw = Buffer.from(auth.slice('Basic '.length), 'base64').toString();

// What a conformant token endpoint does next (RFC 6749 §2.3.1)
const idx = raw.indexOf(':');
const decode = s => new URLSearchParams(`v=${s}`).get('v');
decode(raw.slice(idx + 1)); // 'a b'  — expected 'a+b'

Expected

Encode each half before concatenation, e.g. encodeURIComponent with the !'()* set escaped (matching the Python SDK's quote(value, safe=""), which leaves ~ raw so Entra-style Q~… secrets stay byte-identical), so the server recovers exactly the configured values.

Scope

The same code exists on the v1.x branch (src/client/auth.ts:358). I've opened #3039 with a fix and tests for main and can send the v1.x equivalent if you want it.


Disclosure per the AI contribution policy: this issue was written with Claude Code (an AI coding assistant) under my direction, based on a bug I verified locally against the code above; the reproduction and the RFC citation were checked by hand.

主要言語
TypeScript
スター
13.8k
フォーク
2.5k
平均マージ
6日 23時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/typescript-sdk のほかの issue

modelcontextprotocol/typescript-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。