mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Preserve ChatGPT auth for trusted staging MCP servers (#36983)
## What changed - Treat an MCP server as trusted for ChatGPT authentication when its origin matches the configured HTTPS `chatgpt-staging.com` host or one of its subdomains. - Continue trusting the production ChatGPT origin and falling back to OAuth for other transports and origins. ## Testing - Cover both the staging apex domain and a staging subdomain. GitOrigin-RevId: 1b1d06ab214141d39eb38d46de9dfb74e6fedb3e
This commit is contained in:
1 parent
b9ba969f39
commit
bf05737da4
2 files changed
+52
-13
No files matched your search
@@ -269,6 +269,38 @@ pub fn effective_mcp_servers(
|
||||
effective_mcp_servers_from_configured(configured_mcp_servers(config), config, auth)
|
||||
}
|
||||
|
||||
fn is_trusted_chatgpt_mcp_server(
|
||||
transport: &McpServerTransportConfig,
|
||||
chatgpt_base_url: &str,
|
||||
) -> bool {
|
||||
let McpServerTransportConfig::StreamableHttp { url, .. } = transport else {
|
||||
return false;
|
||||
};
|
||||
let Ok(server_url) = url::Url::parse(url) else {
|
||||
return false;
|
||||
};
|
||||
if !matches!(server_url.scheme(), "http" | "https") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if url::Url::parse(CHATGPT_CODEX_BASE_URL)
|
||||
.ok()
|
||||
.is_some_and(|chatgpt_url| server_url.origin() == chatgpt_url.origin())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
url::Url::parse(chatgpt_base_url)
|
||||
.ok()
|
||||
.is_some_and(|staging_url| {
|
||||
staging_url.scheme() == "https"
|
||||
&& staging_url.domain().is_some_and(|host| {
|
||||
host == "chatgpt-staging.com" || host.ends_with(".chatgpt-staging.com")
|
||||
})
|
||||
&& server_url.origin() == staging_url.origin()
|
||||
})
|
||||
}
|
||||
|
||||
/// Converts a materialized server map to its auth-gated runtime view.
|
||||
///
|
||||
/// Compatibility built-ins and extension overlays must already be reflected in
|
||||
@@ -278,24 +310,12 @@ pub fn effective_mcp_servers_from_configured(
|
||||
config: &McpConfig,
|
||||
auth: Option<&CodexAuth>,
|
||||
) -> HashMap<String, EffectiveMcpServer> {
|
||||
let chatgpt_origin = url::Url::parse(CHATGPT_CODEX_BASE_URL)
|
||||
.ok()
|
||||
.map(|url| url.origin());
|
||||
let mut servers = configured_servers
|
||||
.into_iter()
|
||||
.map(|(name, mut server)| {
|
||||
match server.auth.clone() {
|
||||
McpServerAuth::ChatGpt => {
|
||||
let server_origin = match &server.transport {
|
||||
McpServerTransportConfig::StreamableHttp { url, .. } => {
|
||||
url::Url::parse(url)
|
||||
.ok()
|
||||
.filter(|url| matches!(url.scheme(), "http" | "https"))
|
||||
.map(|url| url.origin())
|
||||
}
|
||||
McpServerTransportConfig::Stdio { .. } => None,
|
||||
};
|
||||
if server_origin.as_ref() != chatgpt_origin.as_ref() {
|
||||
if !is_trusted_chatgpt_mcp_server(&server.transport, &config.chatgpt_base_url) {
|
||||
server.auth = McpServerAuth::OAuth;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user