fix(server): accept case-insensitive MCP bearer schemes#23782

merged8
main
GitHub fork: fix/23710-mcp-authorization
openedOct 22, 2026byRRish-it
View on GitHubTwo-way sync enabledPR last imported Nov 1, 2026

Problem

Both the MCP middleware and the shared auth parser require the exact Bearer prefix. A valid provider or OAuth client token sent as bearer or bEaReR is rejected before verification. Missing Authorization headers and unsupported schemes also produce the same diagnostic.

Change

Reuse EnvironmentAuth.parseBearerToken in the MCP middleware and match the scheme case-insensitively. Token extraction and verification stay unchanged. Rejections now distinguish missing headers, unsupported schemes, empty bearer credentials, and unknown or expired tokens using fixed reasons that contain no credentials.

The shared parser also accepts these scheme spellings for ordinary HTTP authentication and WebSocket upgrades. Existing cookie fallback protections, MCP audience restrictions, scopes, revocation, and OAuth challenges remain covered by focused tests.

Scope and approval

Addresses https://github.com/pingdotgg/t3code/issues/23710. This is a focused fix for an obvious Authorization-header parsing defect: two production files, with regression coverage in the three existing test files. It adds no configuration, dependency, or OAuth flow changes.

This does not establish the cause of the reporter’s ChatGPT connection failure; the report does not show which Authorization header that client sent.

Verification

  • Before production edits, the focused regression failed: lowercase/mixed-case provider and OAuth credentials were rejected, and missing/unsupported headers had the same diagnostic. The same regression passed after the fix (5 tests).

  • Ran vp run check:changed e54e71d725b6eef166ee9b85137c09e051cff342 twice in separate processes: formatting, lint, Knip, affected typechecks, and all 45 adjacent tests passed both times. Also ran fresh server/scripts typechecks with vp run --no-cache --filter t3 --filter @t3tools/scripts typecheck.

  • Existing registry, HTTP auth, session-store, and DPoP suites: 27 tests passed.

  • Isolated runtime reproduction, using disposable credentials for both provider and actual OAuth client authentication:

    text
    1 before after
    2Bearer 200 200
    3bearer / bEaReR 401 200
    4missing / unsupported / empty 401 401
    5altered token case / revoked 401 401
  • Exercised registration, pairing approval, PKCE exchange, and MCP initialization against the full application locally and through T3 Connect. All three scheme spellings succeeded; MCP tokens remained rejected by ordinary HTTP auth. The developer also connected ChatGPT through OAuth to the isolated instance.

After fast-forwarding onto main at e54e71d725b6, committed the fix in three steps: shared auth parsing (e6df999ef), MCP parser reuse (eceba02d6), and rejection diagnostics (2b4471d35). The committed patch matches the reviewed working-tree patch exactly. Re-ran all 45 adjacent tests and the isolated provider/OAuth runtime reproduction from committed HEAD; both passed.

The full-application local/tunnel and ChatGPT OAuth checks above were performed before committing. That test instance is now offline, so those checks were not repeated after committing. Native clients and an actual ChatGPT tool invocation were not verified. CI has not run yet.

Implemented with GPT-6 in the Codex harness.

Checks

22 successful · 14 skipped
All checks passed
98f5edd

Added 3 commits

  • fix(mcp): distinguish authorization rejection reasons2b4471d
  • fix(auth): accept case-insensitive bearer schemese6df999
  • fix(mcp): reuse bearer parsing for provider and OAuth credentialseceba02
Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between df3986420440ca217d584e2b9661e47a571d64dc and 98f5edde849934849d562424f7a321b0ddc82803.

Files selected for processing: 5
  • apps/server/src/auth/EnvironmentAuth.test.ts
  • apps/server/src/auth/EnvironmentAuth.ts
  • apps/server/src/auth/McpOAuth.test.ts
  • apps/server/src/mcp/McpHttpServer.test.ts
  • apps/server/src/mcp/McpHttpServer.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The server now parses Bearer authorization schemes without case-sensitive matching. MCP HTTP authentication uses the shared parser and logs distinct reasons for rejected credentials. Tests cover scheme casing, rejected credentials, and revoked credentials.

Changes: Bearer authentication

Layer / File(s)Summary
Bearer token parsing and authentication tests
apps/server/src/auth/EnvironmentAuth.ts, apps/server/src/auth/EnvironmentAuth.test.ts, apps/server/src/auth/McpOAuth.test.ts
parseBearerToken is exported and accepts case variations of the Bearer scheme. Tests cover those variations, including HTTP and WebSocket authentication.
MCP HTTP bearer authentication
apps/server/src/mcp/McpHttpServer.ts, apps/server/src/mcp/McpHttpServer.test.ts
MCP HTTP authentication uses parseBearerToken. Rejection warnings distinguish missing headers, unsupported schemes, empty bearer tokens, and unknown or expired tokens. Tests cover accepted, rejected, and revoked credentials.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • pingdotgg/t3code#23710 reports the same MCP Authorization scheme defect. This change accepts bearer schemes with any letter case and separates missing-header and unsupported-scheme rejection reasons.

Suggested reviewers: juliusmarminge, maria-rcks

Merge Risk: Minimal · up to 98f5e

Bearer scheme casing is accepted consistently, with no identified merge-blocking issue.

Pre-merge checks: 4
Check nameStatusExplanation
Title checkThe title clearly and concisely describes the primary change: accepting case-insensitive MCP Bearer schemes.
Description checkThe description includes all required sections and provides clear problem context, implementation details, scope justification, focused verification results, and known verification limits.
Linked Issues checkCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkCheck skipped because no linked issues were found for this pull request.
Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Added 3 commits

  • Merge commit '044f07257c9684ae4543bd1e1ebf9c394e9e3830' into fix/23710-mcp-authorizationafe636f
  • fix(server): merge main into MCP authorization fix8f9a395
  • fix(server): mark MCP auth test session as localdf39864

Note

Written by gpt-6.1-sol on behalf of Maria

Merged current main without rebasing and preserved both sides' auth coverage. Updated the regression tests for the RPC socket argument, MCP settings layer, and explicit local OAuth session flag (peerLink: false). Production behavior and the original five-file scope are preserved.

Blacksmith vp run check:changed github/main passed: formatting, lint, Knip, GraphQL validation, three affected package typechecks, and 61 tests. The HTTP transport tests exercise provider and actual OAuth credentials with Bearer, bearer, and bEaReR; invalid and revoked tokens still return 401 without leaking credentials. Browser, native clients, remote relay, and ChatGPT integration were not rechecked in this run.

Note

Written by gpt-6.1-sol on behalf of Maria

Verified in a real dev environment

verified unchanged head df3986420440ca217d584e2b9661e47a571d64dc on this linux vm. reproduced on github/main (ce9e016406) first, then stopped main before starting the pr. both used isolated state, vp i, background dev servers, repo playwright and /usr/bin/google-chrome.

created the repo project and threads through the web ui. real codex gpt-6.1-sol turns completed orchestrator_capabilities on both versions. registered an actual oauth client, approved read-only access in the browser, received its loopback callback, and exchanged the code with pkce. no mocks or fixtures.

text
1 main pr
2OAuth Bearer initialize / tools/list 200 / 200 200 / 200
3OAuth bearer / bEaReR initialize 401 / 401 200 / 200
4real Codex credential, all 3 spellings initialize + tools/list 200
5ordinary HTTP bearer / bEaReR unauthenticated authenticated
6WebSocket bearer / bEaReR upgrade 401 / 401 101 / 101
7missing / Basic / empty / altered token 401 401
8MCP token on ordinary HTTP rejected rejected

on the pr, lowercase and mixed-case oauth credentials also listed all 68 tools. a real project-list invocation succeeded with bEaReR. read-only access rejected a thread rename with capability_denied. revoking the client in settings made all three spellings return 401. the four rejection reasons appeared in server logs without either credential; response bodies and headers also contained no credentials.

blacksmith vp run check:changed 955e2bfbb5c092c54ad795c8d379fec99702a6b5 passed formatting, lint, knip, graphql validation, three package typechecks and 61 tests. the head also has 29 successful ci checks, with none failing or pending. no code changes or push were needed.

short runtime transcript

Not verified

native desktop, ios/android, remote relay/t3 connect, external chatgpt connector, other providers, and long-duration expiration were not exercised. this verifies the authorization parsing fix. the original external chatgpt failure remains unverified. uploaded video playback and seeking were checked in t3's browser.

Added 2 commits

  • Merge main into fix/23710-mcp-authorization2e25f30
  • test(server): provide the managed policy to the MCP bearer scheme test98f5edd