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
2026-09-07 17:26:10 +00:00
committed by copyberry
parent adee0b04fa
commit f326857cf4
11 changed files with 587 additions and 68 deletions
+37
View File
@@ -104,6 +104,18 @@ struct StandardJwtClaims {
exp: Option<i64>,
}
#[derive(Deserialize)]
struct AccountUserClaims {
#[serde(rename = "https://api.openai.com/auth")]
auth: Option<AccountUserAuthClaims>,
}
#[derive(Deserialize)]
struct AccountUserAuthClaims {
chatgpt_account_user_id: Option<String>,
chatgpt_account_id: Option<String>,
}
#[derive(Debug, Error)]
pub enum IdTokenInfoError {
#[error("invalid ID token format")]
@@ -134,6 +146,31 @@ pub fn parse_jwt_expiration(jwt: &str) -> Result<Option<DateTime<Utc>>, IdTokenI
.and_then(|exp| DateTime::<Utc>::from_timestamp(exp, 0)))
}
// Keep membership parsing separate from ordinary auth claims: a malformed optional
// membership must disable local verification without breaking an otherwise valid login.
// Both paths share decode_jwt_payload for the JWT envelope.
pub(crate) fn parse_chatgpt_account_user_id(
jwt: &str,
account_id: &str,
) -> Result<Option<String>, IdTokenInfoError> {
if account_id.is_empty() || account_id.trim() != account_id {
return Ok(None);
}
if jwt.split('.').count() != 3 {
return Err(IdTokenInfoError::InvalidFormat);
}
let claims: AccountUserClaims = decode_jwt_payload(jwt)?;
let Some(auth) = claims.auth else {
return Ok(None);
};
if auth.chatgpt_account_id.as_deref() != Some(account_id) {
return Ok(None);
}
Ok(auth
.chatgpt_account_user_id
.filter(|id| !id.is_empty() && id.trim() == id.as_str()))
}
pub fn parse_chatgpt_jwt_claims(jwt: &str) -> Result<IdTokenInfo, IdTokenInfoError> {
let claims: IdClaims = decode_jwt_payload(jwt)?;
let email = claims