mirror of
https://github.com/openai/codex.git
synced 2026-11-17 14:58:36 +00:00
Restrict hosted MCP credentials to local environments (#36306)
## Why Executor-owned MCP servers must not receive hosted ChatGPT actor credentials or credentials from the host's OAuth store. ## What changed - Provide the ChatGPT auth provider and consult stored OAuth credentials only for MCP servers in the local environment. - Require non-local servers configured with `auth = "chatgpt"` to supply a non-empty, valid static `Authorization` header. Reject environment-backed authorization so host secrets are not resolved for an executor-owned server. - Report unsupported authentication and fail startup before connecting when an executor-owned server has no acceptable explicit authorization. ## Testing Add coverage for local credential forwarding, non-local credential isolation, static header validation, auth status, OAuth lookup avoidance, and startup rejection. GitOrigin-RevId: e18f1878f260c93d9babd390a5a7eac86172299b
This commit is contained in:
1 parent
f0c30e528a
commit
bf4d3f51ea
5 files changed
+310
-2
No files matched your search
@@ -6,6 +6,7 @@ use std::sync::Arc;
|
||||
use crate::runtime::McpRuntimeContext;
|
||||
use codex_api::SharedAuthProvider;
|
||||
use codex_config::AppToolApproval;
|
||||
use codex_config::McpServerAuth;
|
||||
use codex_config::McpServerConfig;
|
||||
use codex_config::McpServerTransportConfig;
|
||||
use codex_config::types::AuthKeyringBackendKind;
|
||||
@@ -42,6 +43,36 @@ impl EffectiveMcpServer {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn has_explicit_http_authorization(config: &McpServerConfig) -> bool {
|
||||
let McpServerTransportConfig::StreamableHttp {
|
||||
bearer_token_env_var,
|
||||
http_headers,
|
||||
env_http_headers,
|
||||
..
|
||||
} = &config.transport
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
if bearer_token_env_var.is_some()
|
||||
|| env_http_headers
|
||||
.as_ref()
|
||||
.is_some_and(|headers| !headers.is_empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
http_headers.as_ref().is_some_and(|headers| {
|
||||
headers.iter().any(|(name, value)| {
|
||||
name.eq_ignore_ascii_case("authorization")
|
||||
&& !value.trim().is_empty()
|
||||
&& value
|
||||
.bytes()
|
||||
.all(|byte| byte == b'\t' || (byte >= b' ' && byte != 0x7f))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Inputs that determine the identity of a live MCP connection.
|
||||
///
|
||||
/// Tool policy and presentation metadata intentionally do not appear here:
|
||||
@@ -78,7 +109,9 @@ impl McpServerConnectionIdentity {
|
||||
supports_openai_form_elicitation: bool,
|
||||
) -> Self {
|
||||
let config = server.config();
|
||||
let stored_oauth_url = if runtime_auth_provider.is_none() {
|
||||
let stored_oauth_url = if runtime_auth_provider.is_none()
|
||||
&& (!matches!(config.auth, McpServerAuth::ChatGpt) || config.is_local_environment())
|
||||
{
|
||||
match &config.transport {
|
||||
McpServerTransportConfig::StreamableHttp {
|
||||
url,
|
||||
|
||||
Reference in new issue
Block a user