Skip to content

feat(desktop-commander): OAuth 2.1 front door for hosted MCP clients (#13404) - #13488

Merged
dezren39 merged 1 commit into
mainfrom
feat/dc-oauth-13404
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
feat/dc-oauth-13404

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

For #13404: hosted MCP clients (Claude, ChatGPT) connect server-side and cannot pass the Cloudflare Access login at /mcp — they got a 302 to the Access login on every path and found no OAuth discovery. This PR gives the Worker an OAuth 2.1 authorization-server front (src/oauth.ts):

  • Discovery — /.well-known/oauth-protected-resource (both shapes) + /.well-known/oauth-authorization-server, public.
  • Registration — POST /register (RFC 7591), public clients, https / loopback-http redirect URIs, clients stored in the new OAUTH_KV namespace (desktop-commander-oauth, created in the account).
  • Authorize — GET/POST /authorize renders the owner's approval page. It stays behind Access (app re-scoped to /authorize in a separate recorded step) and the Worker verifies the Access JWT itself: RS256 against the team JWKS, audience of the authorize app, owner email. Approval is a CSRF-nonce form POST issuing a single-use, PKCE-bound code (10 min).
  • Token — POST /token: authorization-code exchange (PKCE S256; code consumed on any attempt) → opaque access token (1 h) + rotating refresh token (30 d); codes/tokens stored in KV under their SHA-256.
  • /mcp gate — live OAuth Bearer, or the new MACHINE_BEARER Worker secret (constant-time compare); otherwise 401 with the resource_metadata pointer. Bridge door + proxy core unchanged.
  • Pipeline — publish workflow stages MACHINE_BEARER (GitHub environment secret, set; canonical value in fleet secrets as desktop-commander.machine-bearer) alongside the bridge pair. wrangler.toml / cloudflare.config.ts gain the KV binding and ACCESS_AUD / ACCESS_TEAM_DOMAIN vars in step.

Verification: npm test 21/21 (proxy contract re-pointed at the new gate; OAuth suite uses a real in-test RSA keypair as the Access team key — discovery, DCR validation, assertion rejection, plain-PKCE rejection, full approve→exchange→call flow, code single-use, wrong-verifier burn, refresh rotation, deny redirect) and npm run typecheck clean, both on the laptop.


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…13404)

Claude and ChatGPT connect to the MCP endpoint from their own
servers and cannot pass a Cloudflare Access login at /mcp — every
path on commander.security.cab answered them with a 302 to the
Access login, and there was no OAuth discovery to find. The Worker
now runs an OAuth 2.1 authorization server (src/oauth.ts):

- Public discovery: /.well-known/oauth-protected-resource (both
  shapes) and /.well-known/oauth-authorization-server.
- POST /register: dynamic client registration, public clients,
  https / loopback-http redirect URIs, stored in the new OAUTH_KV
  namespace (desktop-commander-oauth).
- GET/POST /authorize: the approval page — the one path that stays
  behind Access (the app is re-scoped to /authorize separately).
  The Worker verifies the Access JWT itself (RS256 vs the team
  JWKS, audience, owner email) before rendering; approval is a
  CSRF-nonce form POST issuing a single-use PKCE-bound code.
- POST /token: authorization-code exchange (PKCE S256; the code is
  consumed on any exchange attempt) plus rotating refresh tokens.
  Codes and tokens are stored in KV under their SHA-256.
- /mcp takes a live OAuth Bearer or the new MACHINE_BEARER secret;
  anything else gets a 401 with the resource_metadata pointer.
  The bridge door and the proxy core are unchanged.

The publish workflow now also stages MACHINE_BEARER (GitHub
environment secret; canonical value in fleet secrets as
desktop-commander.machine-bearer) into the version secrets file.
wrangler.toml and cloudflare.config.ts gain the OAUTH_KV binding
and the ACCESS_AUD / ACCESS_TEAM_DOMAIN vars, kept in step.

Tests: 21 green (proxy contract re-pointed at the new gate, plus an
OAuth suite with a real in-test RSA keypair standing in for the
Access team key: discovery, DCR validation, assertion rejection,
plain-PKCE rejection, full approve-exchange-call flow, code
single-use, wrong-verifier burn, refresh rotation, deny redirect).
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 62ff140d-57a0-4249-8bd6-4ef1fbc17f8f
Commits

Reviewing files that changed from the base of the PR and between 2d65edd and e1444ca.

Files selected for processing: 9

  • .github/workflows/desktop-commander-worker-publish.yml
  • pkgs/desktop-commander/worker/README.md
  • pkgs/desktop-commander/worker/cloudflare.config.ts
  • pkgs/desktop-commander/worker/src/index.ts
  • pkgs/desktop-commander/worker/src/oauth.ts
  • pkgs/desktop-commander/worker/test/memory-kv.ts
  • pkgs/desktop-commander/worker/test/oauth.test.ts
  • pkgs/desktop-commander/worker/test/proxy.test.ts
  • pkgs/desktop-commander/worker/wrangler.toml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T17:09:33.888463Z e1444ca PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 4421467 into main Nov 23, 2026
3 checks passed
@dezren39
dezren39 deleted the feat/dc-oauth-13404 branch November 23, 2026 17:08
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.

1 participant