mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Enforce application network policy in standalone MCP commands (#52215)
## Why Standalone MCP commands must honor `application.network` restrictions during OAuth discovery and login, even when the MCP server is allowed by its identity requirements. ## What changed - Apply local network policy to cloud configuration bootstrap authentication and activate the effective policy on the loaded CLI configuration. - Load `codex mcp add` through the shared cloud configuration loader and use its resolved `codex_home` when saving server configuration. - Block disallowed OAuth discovery requests before connecting while preserving the ability to save a server when discovery is unavailable. ## Testing Add isolated regression tests for blocked MCP discovery and login, discovery with network policy disabled, allowed and denied HTTPS destinations, and rejection of malformed managed network policy. Connection checks verify that denied requests never reach a TCP listener. GitOrigin-RevId: f91401b51d6e6b9472bb01838f0d0903f83d62f3
This commit is contained in:
@@ -258,7 +258,8 @@ impl McpCli {
|
||||
run_get(&config, args).await?;
|
||||
}
|
||||
McpSubcommand::Add(args) => {
|
||||
run_add(&config_overrides, args).await?;
|
||||
let config = cloud_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
run_add(&config, args).await?;
|
||||
}
|
||||
McpSubcommand::Remove(args) => {
|
||||
run_remove(&config_overrides, args).await?;
|
||||
@@ -293,15 +294,7 @@ async fn validate_profile_v2_migration(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn run_add(config_overrides: &CliConfigOverrides, add_args: AddArgs) -> Result<()> {
|
||||
// Validate any provided overrides even though they are not currently applied.
|
||||
let overrides = config_overrides
|
||||
.parse_overrides()
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
let config = Config::load_with_cli_overrides(overrides)
|
||||
.await
|
||||
.context("failed to load configuration")?;
|
||||
|
||||
async fn run_add(config: &Config, add_args: AddArgs) -> Result<()> {
|
||||
let AddArgs {
|
||||
name,
|
||||
transport_args,
|
||||
@@ -309,7 +302,7 @@ async fn run_add(config_overrides: &CliConfigOverrides, add_args: AddArgs) -> Re
|
||||
|
||||
validate_server_name(&name)?;
|
||||
|
||||
let codex_home = find_codex_home().context("failed to resolve CODEX_HOME")?;
|
||||
let codex_home = &config.codex_home;
|
||||
|
||||
let (transport, oauth_client_id, oauth_client_secret, client_registration, oauth_resource) =
|
||||
match transport_args {
|
||||
@@ -451,13 +444,13 @@ async fn run_add(config_overrides: &CliConfigOverrides, add_args: AddArgs) -> Re
|
||||
tools: HashMap::new(),
|
||||
};
|
||||
|
||||
let mut servers = load_global_mcp_servers(&codex_home)
|
||||
let mut servers = load_global_mcp_servers(codex_home)
|
||||
.await
|
||||
.with_context(|| format!("failed to load MCP servers from {}", codex_home.display()))?;
|
||||
let credential_name = new_entry.oauth_credential_name(&name);
|
||||
servers.insert(name.clone(), new_entry);
|
||||
|
||||
ConfigEditsBuilder::new(&codex_home)
|
||||
ConfigEditsBuilder::new(codex_home)
|
||||
.replace_mcp_servers(&servers)
|
||||
.apply()
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user