From e6e4c5fa3ace1cbbde9ccb36f8b3bdbb1c09e427 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Thu, 12 Feb 2026 23:57:53 -0800 Subject: [PATCH] chore(core) Restrict model-suggested rules (#11671) ## Summary If the model suggests a bad rule, don't show it to the user. This does not impact the parsing of existing rules, just the ones we show. ## Testing - [x] Added unit tests - [x] Ran locally --- codex-rs/core/src/exec_policy.rs | 158 +++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/codex-rs/core/src/exec_policy.rs b/codex-rs/core/src/exec_policy.rs index de21b8aa3..3cc83c4a4 100644 --- a/codex-rs/core/src/exec_policy.rs +++ b/codex-rs/core/src/exec_policy.rs @@ -35,6 +35,54 @@ const PROMPT_CONFLICT_REASON: &str = const RULES_DIR_NAME: &str = "rules"; const RULE_EXTENSION: &str = "rules"; const DEFAULT_POLICY_FILE: &str = "default.rules"; +static BANNED_PREFIX_SUGGESTIONS: &[&[&str]] = &[ + &["python3"], + &["python3", "-"], + &["python3", "-c"], + &["python"], + &["python", "-"], + &["python", "-c"], + &["py"], + &["py", "-3"], + &["pythonw"], + &["pyw"], + &["pypy"], + &["pypy3"], + &["git"], + &["bash"], + &["bash", "-lc"], + &["sh"], + &["sh", "-c"], + &["sh", "-lc"], + &["zsh"], + &["zsh", "-lc"], + &["/bin/zsh"], + &["/bin/zsh", "-lc"], + &["/bin/bash"], + &["/bin/bash", "-lc"], + &["pwsh"], + &["pwsh", "-Command"], + &["pwsh", "-c"], + &["powershell"], + &["powershell", "-Command"], + &["powershell", "-c"], + &["powershell.exe"], + &["powershell.exe", "-Command"], + &["powershell.exe", "-c"], + &["env"], + &["sudo"], + &["node"], + &["node", "-e"], + &["perl"], + &["perl", "-e"], + &["ruby"], + &["ruby", "-e"], + &["php"], + &["php", "-r"], + &["lua"], + &["lua", "-e"], + &["osascript"], +]; fn is_policy_match(rule_match: &RuleMatch) -> bool { match rule_match { @@ -240,6 +288,10 @@ pub async fn load_exec_policy(config_stack: &ConfigLayerStack) -> Result Result