Skip to content

Let hosted agents connect to MCP with OAuth and an opt-in public URL (#1541) - #1603

Merged
currentbits merged 1 commit into
mainfrom
coder/oauth-2-1-pkce-public-reachability-for-t-ce2911
Oct 11, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/oauth-2-1-pkce-public-reachability-for-t-ce2911

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Hosted agents (ChatGPT connectors, claude.ai) can now reach loopback /mcp through opt-in Tailscale Funnel and sign in with OAuth 2.1 + PKCE. Closes the public-reachability half of #1541.

Changes

  • Settings → Integrations exposes /mcp on the public internet via Tailscale Funnel on HTTPS 8443 (so it does not fight Web Serve on :443). Off by default; the copy states the exposure as clearly as the existing Serve note. Copy public URL once Funnel is up.
  • /mcp accepts the rotating in-app session token only when Host is loopback. A public Host gets 401 + WWW-Authenticate resource metadata and must present a pairing or OAuth bearer.
  • OAuth 2.1 with PKCE S256: protected-resource + AS metadata, dynamic client registration (public clients), in-app consent dialog. Each grant is a pairing row, so revoke cuts it off immediately.

Verification

  • node --test electron/test/mcp-oauth.test.js electron/test/pairing.test.js electron/test/pairing-ipc.test.js electron/test/webAccess.test.js electron/test/webScopes.test.js — 43 passed (OAuth, Funnel, pairing, scopes).
  • Renderer: test/oauthConsent.test.tsx and Settings integrations — passed.
  • electron/test/orch-server.test.js (public Host rejects session token; OAuth grant can call /mcp) passed earlier in this worktree; could not re-run at the end because this checkout has no node_modules of its own and the sibling MCP SDK symlink vanished.
  • Not tested: a live ChatGPT / claude.ai connector sign-in.

Notes for reviewers

  • Public vs local is Host-header based because Funnel makes remoteAddress always 127.0.0.1. A spoofed Host: 127.0.0.1 through Funnel would unlock the session token. Missing Host is no longer treated as loopback.
  • Refresh tokens are reused, not rotated. http redirect URIs must be loopback.
  • Connectors that only allow HTTPS :443 will not reach Funnel on :8443. A hosted relay for machines without Tailscale is out of scope.

cursor-grok-4.6 via Cursor

Made with Cursor

Solenta-Message-Id: a66b02fb-aacf-418c-96de-5f0d77a58cde
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T19:21:51.491370Z 38a2bb9 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.

@currentbits
currentbits merged commit 18ac76a into main Oct 11, 2026
6 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38a2bb916f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread electron/ipc-mcp.js
Comment on lines +219 to +220
} catch (err) {
pairing.setPublicEnabled(ctx.userDataPath, false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve enabled state when Funnel shutdown fails

When the user stops public access and the Tailscale funnel ... off command fails, this catch persists publicEnabled: false even though the Funnel is still serving the endpoint. The app therefore records the user's exposure as disabled while the public route remains active, and a restart will not retry the requested shutdown; restore the previous enabled state on failure or persist the new state only after the CLI operation succeeds.

Useful? React with 👍 / 👎.

Comment thread electron/mcpOauth.js
Comment on lines +155 to +157
const clients = loadClients(userDataPath);
if (clients.length >= MAX_CLIENTS) {
throw new Error(`At most ${MAX_CLIENTS} OAuth clients`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prevent public registrations from exhausting the client table

While Funnel is enabled, /register is unauthenticated, but every registration is persisted and there is no expiration, deduplication, or deletion path. Any remote caller can submit 40 valid registrations and permanently make all subsequent legitimate connector registrations fail with this limit until the user manually edits oauth-clients.json; prune stale clients or make the bounded registration state recoverable.

Useful? React with 👍 / 👎.

Comment thread electron/mcpOauth.js
Comment on lines +206 to +208
createdAt: Date.now(),
};
consents.set(id, pending);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound unauthenticated pending consent requests

A caller that registers one client can repeatedly request public /authorize URLs, and each request inserts a permanent entry into this process-global map and emits another desktop consent notification. Because pending entries have neither a TTL nor a count/rate limit and are removed only when the user explicitly approves or denies them, a remote caller can grow memory and the consent backlog without bound; expire and cap pending requests before inserting them.

Useful? React with 👍 / 👎.

Comment thread electron/mcpOauth.js
Comment on lines +234 to +237
function approveConsent(userDataPath, id, grantInput, opts = {}) {
const pending = takeConsent(id);
const now = opts.now || Date.now();
const created = pairing.createPairing(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain consent until grant creation succeeds

If createPairing fails after this call—for example because 20 active pairings already exist or the pairing file cannot be written—the pending consent has already been deleted. The dialog keeps displaying its local request, but both Allow and Deny then fail as unknown, while the hosted browser polls a 404 forever instead of receiving an OAuth redirect; remove the consent only after successful grant creation or restore it on failure.

Useful? React with 👍 / 👎.

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