Skip to content

Isolate Agent Host MCP OAuth credentials by server and client - #342148

Closed
Harald Kirschner (digitarald) with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-oauth-token-sharing-issue
Closed

Harald Kirschner (digitarald) with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-oauth-token-sharing-issue

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

MCP authentication replies matched pending requests by resource and scopes alone, allowing servers sharing an endpoint to receive the same token. Static OAuth clients also shared provider and credential-cache identities.

  • Route replies: Carry validated server/client identity in optional _meta; resolve only matching callbacks, and reject ambiguous legacy replies across distinct identities.
  • Isolate credentials: Include configured client ID in dynamic provider IDs and partition forwarded-token and reconnect caches by MCP identity.
  • Regression coverage: Exercise concurrent same-resource requests with different server names and client IDs, plus legacy matching and cache isolation.
_meta: {
	'vscode.mcp.authenticationIdentity': {
		serverName: 'slack-a',
		clientId: 'slack-a-client'
	}
}

Copilot AI balanced review requested due to automatic review settings October 16, 2026 18:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

Copilot AI changed the title [WIP] Fix OAuth token sharing issue in Agent Host Isolate Agent Host MCP OAuth credentials by server and client Oct 16, 2026
@digitarald

Copy link
Copy Markdown
Contributor

Copilot Please make these two targeted changes before merging:

  1. Carry the client-specific provider identity through actual provider creation and storage. getDynamicAuthenticationProviderId(...) now includes the configured client ID, but DynamicAuthProvider in extHostAuthentication.ts still constructs its ID from authorization server + resource only. The Agent Host OAuth flow currently uses this factory, so its two clients still register under the same actual provider ID, while workbench credential lookups use different IDs. Thread one canonical identity through creation, registration, and storage; preserve the distinction between configured clients and restored dynamic registrations. Add a regression test through the real main-thread/extension-host boundary rather than a mock that manufactures the expected ID. This is needed for Agent Host correctness, not a request to expand legacy extension-host functionality.

  2. Preserve exact scope matching when clearing the forwarding cache. The new prefix scan in AgentHostAuthTokenCache.clear(resource, scopes) uses the same delimiter between scope elements and before the MCP identity suffix. Clearing ["read"] therefore also invalidates ["read", "write"], causing redundant handoffs and potentially cancelling unrelated in-flight authentication through the generation check. Use an unambiguous scope-array boundary or structured keys, and add regression coverage for overlapping scope sets, including in-flight entries.

Keep this PR focused: retain the metadata/reply matching and identity partitioning, but do not add a new authentication framework or migrate OAuth ownership as part of this fix.

Copilot AI commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Copilot Please make these two targeted changes before merging:

  1. Carry the client-specific provider identity through actual provider creation and storage. `getDynamicAuthenticationProviderId(.....

Implemented and pushed as dfb70312. Provider identity now flows through extension-host construction, registration, and storage, with restored registrations retaining their legacy base ID. Cache clearing now preserves exact scope-set boundaries, including in-flight entries. The focused browser suites and ESLint pass; client typecheck is blocked by missing Electron/original-fs dependencies.

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.

Agent Host: MCP servers sharing a resource receive the same OAuth token despite distinct client IDs

3 participants