mirror of
https://github.com/openai/codex.git
synced 2026-11-22 15:15:18 +00:00
Prompt before trusting local project directories (#36960)
## Why Trusting a directory enables project-local config, hooks, and exec policies, which can increase exposure to prompt injection. Require an explicit decision instead of automatically trusting projects whose trust level is unset. ## What changed - Add a directory-trust step to TUI onboarding, with options to trust and continue or quit. - Apply trust to the Git repository root when starting from a subdirectory, persist the decision, and reload config before continuing. - Keep the prompt active and show the config error when trust cannot be persisted. Skip the prompt for remote workspaces and projects with an explicit trust level. ## Testing - Cover trust-screen rendering, keyboard selection, persistence failures, and prompt visibility for explicit trust and Windows sandbox states. GitOrigin-RevId: 850e6f54aec84d584cd161348ecdb1da89aaabd4
This commit is contained in:
1 parent
92689b6b7b
commit
17801b4206
12 files changed
+690
-388
No files matched your search
@@ -9642,41 +9642,6 @@ async fn active_project_does_not_match_configured_alias_for_canonical_cwd() -> a
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn active_project_honors_custom_project_root_markers() -> anyhow::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let project_root = codex_home.path().join("project");
|
||||
let nested = project_root.join("nested");
|
||||
std::fs::create_dir_all(&nested)?;
|
||||
std::fs::write(project_root.join(".hg"), "")?;
|
||||
let project_key = project_root.display().to_string().replace('\\', "\\\\");
|
||||
std::fs::write(
|
||||
codex_home.path().join(CONFIG_TOML_FILE),
|
||||
format!(
|
||||
r#"project_root_markers = [".hg"]
|
||||
|
||||
[projects."{project_key}"]
|
||||
trust_level = "untrusted"
|
||||
"#,
|
||||
),
|
||||
)?;
|
||||
|
||||
let config = ConfigBuilder::without_managed_config_for_tests()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.harness_overrides(ConfigOverrides {
|
||||
cwd: Some(nested),
|
||||
..Default::default()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
assert_eq!(
|
||||
config.active_project.trust_level,
|
||||
Some(TrustLevel::Untrusted)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_default_oss_provider() -> std::io::Result<()> {
|
||||
let temp_dir = TempDir::new()?;
|
||||
@@ -10621,10 +10586,6 @@ save_fields_resolved_from_model_catalog = false
|
||||
#[tokio::test]
|
||||
async fn debug_config_lockfile_load_path_loads_lock_from_nested_table() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let project_root = codex_home.path().join("project");
|
||||
let nested = project_root.join("nested");
|
||||
std::fs::create_dir_all(&nested)?;
|
||||
std::fs::write(project_root.join(".hg"), "")?;
|
||||
let lock_path = codex_home.path().join("session.config.lock.toml");
|
||||
std::fs::write(
|
||||
&lock_path,
|
||||
@@ -10640,9 +10601,7 @@ codex_version = "older-version"
|
||||
std::fs::write(
|
||||
codex_home.path().join(CONFIG_TOML_FILE),
|
||||
format!(
|
||||
r#"project_root_markers = [".hg"]
|
||||
|
||||
[debug.config_lockfile]
|
||||
r#"[debug.config_lockfile]
|
||||
load_path = '{}'
|
||||
allow_codex_version_mismatch = true
|
||||
save_fields_resolved_from_model_catalog = false
|
||||
@@ -10653,14 +10612,10 @@ save_fields_resolved_from_model_catalog = false
|
||||
|
||||
let config = ConfigBuilder::without_managed_config_for_tests()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(nested))
|
||||
.fallback_cwd(Some(codex_home.path().to_path_buf()))
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
assert_eq!(
|
||||
config.config_layer_stack.project_root(),
|
||||
Some(&project_root.abs())
|
||||
);
|
||||
assert!(config.config_lock_toml.is_some());
|
||||
assert!(config.config_lock_allow_codex_version_mismatch);
|
||||
assert!(!config.config_lock_save_fields_resolved_from_model_catalog);
|
||||
|
||||
@@ -1488,8 +1488,7 @@ impl ConfigBuilder {
|
||||
vec![lock_layer],
|
||||
config_layer_stack.requirements().clone(),
|
||||
config_layer_stack.requirements_toml().clone(),
|
||||
)?
|
||||
.with_project_root(config_layer_stack.project_root().cloned());
|
||||
)?;
|
||||
let mut config = Config::load_config_with_layer_stack(
|
||||
LOCAL_FS.as_ref(),
|
||||
lock_config_toml,
|
||||
@@ -1799,7 +1798,6 @@ impl Config {
|
||||
.requirements_toml()
|
||||
.clone(),
|
||||
)?
|
||||
.with_project_root(refreshed_config.config_layer_stack.project_root().cloned())
|
||||
.with_user_and_project_exec_policy_rules_ignored(
|
||||
refreshed_config
|
||||
.config_layer_stack
|
||||
@@ -3348,21 +3346,12 @@ impl Config {
|
||||
.into_iter()
|
||||
.map(|path| AbsolutePathBuf::resolve_path_against_base(path, resolved_cwd.as_path()))
|
||||
.collect();
|
||||
let project_root = config_layer_stack
|
||||
.project_root()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| resolved_cwd.clone());
|
||||
let repo_root = resolve_root_git_project_for_trust(fs, &resolved_cwd).await;
|
||||
let active_project = cfg
|
||||
.get_active_project(
|
||||
resolved_cwd.as_path(),
|
||||
Some(project_root.as_path()),
|
||||
repo_root.as_ref().map(AbsolutePathBuf::as_path),
|
||||
)
|
||||
.or_else(|| {
|
||||
repo_root.as_ref().and_then(|repo_root| {
|
||||
cfg.get_active_project(repo_root.as_path(), /*repo_root*/ None)
|
||||
})
|
||||
})
|
||||
.unwrap_or(ProjectConfig { trust_level: None });
|
||||
let permission_config_syntax = resolve_permission_config_syntax(
|
||||
&config_layer_stack,
|
||||
|
||||
Reference in new issue
Block a user