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

Đang mở
#3,263 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@gdut4140 đang làm issue này rồi.

Từ ngày 16/10/2026.

  • #3039 của @gdut4140 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
authentication, backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
13.8k
Fork
2.5k
Merge trung bình
6 ngày 23 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/typescript-sdk

Tất cả issue của modelcontextprotocol/typescript-sdk

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.