Restrict MCP user verification and add workspace-scoped identity (#43524)

## Why

Configured MCP servers must not be able to request user verification, even when they reuse the hosted apps server name. Local verification identity selection also needs to distinguish a user's workspace memberships.

## What changed

- Advertise `userVerification` only to the host-owned apps MCP server and cancel verification requests from other servers before prompting the client.
- Add `CodexAuth::get_chatgpt_account_user_id()` to read the access token's opaque `chatgpt_account_user_id` only when its workspace matches the selected account. Missing or malformed claims return no identity, without falling back to another user ID or breaking ordinary authentication.

## Testing

Add coverage for capability filtering, rejection of configured servers including those using the hosted apps name, and account-user identity selection with malformed or mismatched claims. Add an MCP round-trip test showing that verification waits for a client response even in full access mode, returns the supplied proof, and discards response metadata.

GitOrigin-RevId: 156e83d5a0302c013b85e564b46b4bfe858cbdb0
This commit is contained in:
riley-oai authored and copyberry committed 2026-09-07 17:26:10 +00:00
1 parent adee0b04fa
commit f326857cf4
11 files changed
+587 -68

No files matched your search

+18
View File
@@ -59,6 +59,7 @@ use crate::default_client::create_client;
use crate::default_client::create_default_auth_client;
use crate::outbound_proxy::AuthRouteConfig;
use crate::token_data::TokenData;
use crate::token_data::parse_chatgpt_account_user_id;
use crate::token_data::parse_chatgpt_jwt_claims;
use crate::token_data::parse_jwt_expiration;
use codex_config::ManagedAuthPolicy;
@@ -631,6 +632,19 @@ impl CodexAuth {
}
}
/// Returns the access token's opaque account-user identity only when its workspace
/// matches the selected account. Missing claims never fall back to a user id.
/// Unlike `get_chatgpt_user_id`, this identifies one workspace membership, so keys
/// are not shared across a person's workspaces. Workload-identity exchange claims
/// describe an agent identity and cannot select a human verification credential.
/// This is local identity selection, not access-token or proof validation.
pub fn get_chatgpt_account_user_id(&self) -> Option<String> {
let tokens = self.get_current_token_data()?;
parse_chatgpt_account_user_id(&tokens.access_token, tokens.account_id.as_deref()?)
.ok()
.flatten()
}
/// Account-facing plan classification derived from the current auth.
/// Returns a high-level `AccountPlanType` (e.g., Free/Plus/Pro/Team/…)
/// for UI or product decisions based on the user's subscription.
@@ -3070,3 +3084,7 @@ mod tests;
#[cfg(test)]
#[path = "change_state_tests.rs"]
mod change_state_tests;
#[cfg(test)]
#[path = "account_user_id_tests.rs"]
mod account_user_id_tests;