-
Notifications
You must be signed in to change notification settings - Fork 8.1k
fix(core): canonicalize wrapper approvals and support heredoc prefix … #10941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dylan-hurd-oai
merged 11 commits into
main
from
codex/viyatb/execpolicy-heredoc-canonicalization
Feb 10, 2026
+440
−10
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3964f17
fix(core): canonicalize wrapper approvals and support heredoc prefix …
viyatb-oai 826a6ad
fix(core): make heredoc attachment matching explicit
viyatb-oai e683b6f
fix(core): skip auto execpolicy amendment for heredoc fallback
viyatb-oai 22179d8
refactor(core): simplify heredoc fallback parse result plumbing
viyatb-oai fd03b3f
Merge remote-tracking branch 'origin/main' into codex/viyatb/execpoli…
viyatb-oai a929f4e
fix(core): preserve mainline exec_policy feature test context
viyatb-oai 6404ad3
fix(core): tighten heredoc fallback parsing
viyatb-oai cd8c297
docs(core): clarify heredoc fallback amendment behavior
viyatb-oai 8bf5e41
test: add execpolicy prefix safety matrix script
viyatb-oai 631cd90
chore: remove local-only execpolicy matrix script
viyatb-oai 39fbd7f
Merge branch 'main' into codex/viyatb/execpolicy-heredoc-canonicaliza…
dylan-hurd-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| use crate::bash::extract_bash_command; | ||
| use crate::bash::parse_shell_lc_plain_commands; | ||
| use crate::powershell::extract_powershell_command; | ||
|
|
||
| const CANONICAL_BASH_SCRIPT_PREFIX: &str = "__codex_shell_script__"; | ||
| const CANONICAL_POWERSHELL_SCRIPT_PREFIX: &str = "__codex_powershell_script__"; | ||
|
|
||
| /// Canonicalize command argv for approval-cache matching. | ||
| /// | ||
| /// This keeps approval decisions stable across wrapper-path differences (for | ||
| /// example `/bin/bash -lc` vs `bash -lc`) and across shell wrapper tools while | ||
| /// preserving exact script text for complex scripts where we cannot safely | ||
| /// recover a tokenized command sequence. | ||
| pub(crate) fn canonicalize_command_for_approval(command: &[String]) -> Vec<String> { | ||
| if let Some(commands) = parse_shell_lc_plain_commands(command) | ||
| && let [single_command] = commands.as_slice() | ||
| { | ||
| return single_command.clone(); | ||
| } | ||
|
|
||
| if let Some((_shell, script)) = extract_bash_command(command) { | ||
| let shell_mode = command.get(1).cloned().unwrap_or_default(); | ||
| return vec![ | ||
| CANONICAL_BASH_SCRIPT_PREFIX.to_string(), | ||
| shell_mode, | ||
| script.to_string(), | ||
| ]; | ||
| } | ||
|
|
||
| if let Some((_shell, script)) = extract_powershell_command(command) { | ||
| return vec![ | ||
| CANONICAL_POWERSHELL_SCRIPT_PREFIX.to_string(), | ||
| script.to_string(), | ||
| ]; | ||
| } | ||
|
|
||
| command.to_vec() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::canonicalize_command_for_approval; | ||
| use pretty_assertions::assert_eq; | ||
|
|
||
| #[test] | ||
| fn canonicalizes_word_only_shell_scripts_to_inner_command() { | ||
| let command_a = vec![ | ||
| "/bin/bash".to_string(), | ||
| "-lc".to_string(), | ||
| "cargo test -p codex-core".to_string(), | ||
| ]; | ||
| let command_b = vec![ | ||
| "bash".to_string(), | ||
| "-lc".to_string(), | ||
| "cargo test -p codex-core".to_string(), | ||
| ]; | ||
|
|
||
| assert_eq!( | ||
| canonicalize_command_for_approval(&command_a), | ||
| vec![ | ||
| "cargo".to_string(), | ||
| "test".to_string(), | ||
| "-p".to_string(), | ||
| "codex-core".to_string(), | ||
| ] | ||
| ); | ||
| assert_eq!( | ||
| canonicalize_command_for_approval(&command_a), | ||
| canonicalize_command_for_approval(&command_b) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn canonicalizes_heredoc_scripts_to_stable_script_key() { | ||
| let script = "python3 <<'PY'\nprint('hello')\nPY"; | ||
| let command_a = vec![ | ||
| "/bin/zsh".to_string(), | ||
| "-lc".to_string(), | ||
| script.to_string(), | ||
| ]; | ||
| let command_b = vec!["zsh".to_string(), "-lc".to_string(), script.to_string()]; | ||
|
|
||
| assert_eq!( | ||
| canonicalize_command_for_approval(&command_a), | ||
| vec![ | ||
| "__codex_shell_script__".to_string(), | ||
| "-lc".to_string(), | ||
| script.to_string(), | ||
| ] | ||
| ); | ||
| assert_eq!( | ||
| canonicalize_command_for_approval(&command_a), | ||
| canonicalize_command_for_approval(&command_b) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn canonicalizes_powershell_wrappers_to_stable_script_key() { | ||
| let script = "Write-Host hi"; | ||
| let command_a = vec![ | ||
| "powershell.exe".to_string(), | ||
| "-NoProfile".to_string(), | ||
| "-Command".to_string(), | ||
| script.to_string(), | ||
| ]; | ||
| let command_b = vec![ | ||
| "powershell".to_string(), | ||
| "-Command".to_string(), | ||
| script.to_string(), | ||
| ]; | ||
|
|
||
| assert_eq!( | ||
| canonicalize_command_for_approval(&command_a), | ||
| vec![ | ||
| "__codex_powershell_script__".to_string(), | ||
| script.to_string(), | ||
| ] | ||
| ); | ||
| assert_eq!( | ||
| canonicalize_command_for_approval(&command_a), | ||
| canonicalize_command_for_approval(&command_b) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn preserves_non_shell_commands() { | ||
| let command = vec!["cargo".to_string(), "fmt".to_string()]; | ||
| assert_eq!(canonicalize_command_for_approval(&command), command); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<scripts don’t bypass approvalsThis parser accepts any
wordnodes verbatim, andparse_shell_lc_single_command_prefixis gated only byscript.contains("<<"). That combination means scripts that merely contain<<(e.g., arithmetic shiftecho $((1<<2))or a here‑string with command substitution likepython3 <<< "$(rm -rf /)") can be reduced to a simple argv prefix and matched byprefix_rule, skipping approvals that previously triggered when word‑only parsing failed. This is a regression in safety:<<in non‑heredoc contexts can now be used to bypass the intended “complex script” fallback. Consider verifying that the AST actually contains a heredoc redirect, and/or rejecting words that include expansions before returning a prefix.Useful? React with 👍 / 👎.