mirror of
https://github.com/openai/codex.git
synced 2026-09-11 20:36:49 +00:00
## What changed - On session startup, remove exact `allow` entries from `rules/default.rules` for command prefixes that Codex no longer suggests as policy amendments. - Record the migration in `.sandbox_migration` so it runs only once, preserving rules created after the migration. - Skip the migration when user and project exec policy rules are ignored. - Expand the protected prefix list across shells, interpreters, package runners, and destructive or privilege-related commands. ## Testing - Cover selective removal, case-insensitive matching, one-time behavior, and the startup path with ignored policy rules. GitOrigin-RevId: a0c60e3f82b9630e621fd034b40462e3ab775102
59 lines
2.1 KiB
Rust
59 lines
2.1 KiB
Rust
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
use tempfile::tempdir;
|
|
|
|
#[tokio::test]
|
|
async fn removes_banned_allow_rules_once() {
|
|
const BANNED_PREFIXES: &[&[&str]] = &[
|
|
&["cmd.exe", "/k"],
|
|
&["git"],
|
|
&["pwsh", "-ec"],
|
|
&["pwsh", "-f"],
|
|
];
|
|
let codex_home = tempdir().expect("create codex home");
|
|
let policy_path = codex_home.path().join("rules/default.rules");
|
|
std::fs::create_dir_all(policy_path.parent().expect("rules directory"))
|
|
.expect("create rules directory");
|
|
std::fs::write(
|
|
&policy_path,
|
|
r#"prefix_rule(pattern=["git"], decision="allow")
|
|
prefix_rule(pattern=["git"], decision="prompt")
|
|
prefix_rule(pattern=["git"], decision="deny")
|
|
prefix_rule(pattern=["git", "status"], decision="allow")
|
|
prefix_rule(pattern=["CMD.EXE", "/K"], decision="allow")
|
|
prefix_rule(pattern=["PWSH", "-EC"], decision="allow")
|
|
prefix_rule(pattern=["PwSh", "-F"], decision="allow")
|
|
network_rule(host="api.github.com", protocol="https", decision="allow")
|
|
"#,
|
|
)
|
|
.expect("write legacy policy");
|
|
|
|
prefix_rule_migration(codex_home.path(), &policy_path, BANNED_PREFIXES)
|
|
.await
|
|
.expect("run sandbox migration");
|
|
assert_eq!(
|
|
std::fs::read_to_string(&policy_path).expect("read migrated policy"),
|
|
r#"prefix_rule(pattern=["git"], decision="prompt")
|
|
prefix_rule(pattern=["git"], decision="deny")
|
|
prefix_rule(pattern=["git", "status"], decision="allow")
|
|
network_rule(host="api.github.com", protocol="https", decision="allow")
|
|
"#
|
|
);
|
|
assert_eq!(
|
|
std::fs::read_to_string(codex_home.path().join(MIGRATION_MARKER_FILENAME))
|
|
.expect("read migration marker"),
|
|
"v1\n"
|
|
);
|
|
|
|
let post_migration_policy = r#"prefix_rule(pattern=["git"], decision="allow")
|
|
"#;
|
|
std::fs::write(&policy_path, post_migration_policy).expect("write post-migration policy");
|
|
prefix_rule_migration(codex_home.path(), &policy_path, BANNED_PREFIXES)
|
|
.await
|
|
.expect("rerun sandbox migration");
|
|
assert_eq!(
|
|
std::fs::read_to_string(&policy_path).expect("read post-migration policy"),
|
|
post_migration_policy
|
|
);
|
|
}
|