Files
codex/codex-rs/config/src/codex_home_symlink.rs
T
jif d13aeb77ea Allow trusted symlinks beneath CODEX_HOME on macOS (#42716)
## What changed

- Add the macOS-only `allow_symlinked_codex_home` user setting. When enabled in the execution host's `$CODEX_HOME/config.toml`, writable roots at or beneath that home may traverse symlinks.
- Keep the exception disabled by default and prevent project config, command-line overrides, and ignored user config from enabling it. Other writable roots remain subject to symlink checks.
- Propagate the resolved setting through local, interactive, and exec-server sandbox paths, including `CODEX_HOME` aliases.
- Explain the opt-out in symlink rejection errors, including that it trusts targets outside `CODEX_HOME` and targets that change between commands.

## Testing

- Add macOS coverage for shell commands, patches, filesystem helpers, process execution, and interactive startup with enabled, disabled, aliased, and out-of-scope homes.

GitOrigin-RevId: 99fcdf611200c9e1b7713cf06f7fdea5bfa7f089
2026-09-04 10:12:03 +00:00

29 lines
1.1 KiB
Rust

//! Resolves the host's symlink opt-out from its already-loaded user config.
use crate::ConfigLayerSource;
use crate::ConfigLayerStack;
use codex_utils_absolute_path::AbsolutePathBuf;
/// Returns the opted-in home without consulting project config or rereading config files.
pub fn allowed_symlinked_codex_home(
config_layer_stack: &ConfigLayerStack,
codex_home: &AbsolutePathBuf,
) -> Option<AbsolutePathBuf> {
let enabled = config_layer_stack
.layers_low_to_high()
.find(|layer| matches!(layer.name, ConfigLayerSource::User { profile: None, .. }))?
.config
.get("allow_symlinked_codex_home")?
.as_bool()?;
if !enabled {
return None;
}
// Preserve a configured alias only when lexical normalization did not change its target.
let alias = std::env::var_os("CODEX_HOME")
.filter(|path| !path.is_empty())
.and_then(|path| AbsolutePathBuf::from_absolute_path(path).ok())
.filter(|path| path.canonicalize().ok().as_ref() == Some(codex_home));
Some(alias.unwrap_or_else(|| codex_home.clone()))
}