Skip to content

fix(core): canonicalize wrapper approvals and support heredoc prefix …#10941

Open
viyatb-oai wants to merge 8 commits intomainfrom
codex/viyatb/execpolicy-heredoc-canonicalization
Open

fix(core): canonicalize wrapper approvals and support heredoc prefix …#10941
viyatb-oai wants to merge 8 commits intomainfrom
codex/viyatb/execpolicy-heredoc-canonicalization

Conversation

@viyatb-oai
Copy link
Collaborator

Summary

  • Reduced repeated approvals for equivalent wrapper commands and fixed execpolicy matching for heredoc-style shell invocations, with minimal behavior change and fail-closed defaults.

Fixes

  1. Canonicalized approval matching for wrappers so equivalent commands map to the same approval intent.
  2. Added heredoc-aware prefix extraction for execpolicy so commands like python3 <<'PY' ... PY match rules such as prefix_rule(["python3"], ...).
  3. Kept fallback behavior conservative: if parsing is ambiguous, existing prompt behavior is preserved.

Edge Cases Covered

  • Wrapper path/name differences: /bin/bash vs bash, /bin/zsh vs zsh.
  • Shell modes: -c and -lc.
  • Heredoc forms: quoted delimiter (<<'PY') and unquoted delimiter (<< PY).
  • Multi-command heredoc scripts are rejected by the fallback
  • Non-heredoc redirections (>, etc.) are not treated as heredoc prefix matches.
  • Complex scripts still fall back to prior behavior rather than expanding permissions.

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3964f175be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 215 to 219
"word" | "number" => {
words.push(child.utf8_text(src.as_bytes()).ok()?.to_owned());
}
// Allow shell constructs that attach IO to a single command without
// changing argv matching semantics for the executable prefix.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Ensure non-heredoc << scripts don’t bypass approvals

This parser accepts any word nodes verbatim, and parse_shell_lc_single_command_prefix is gated only by script.contains("<<"). That combination means scripts that merely contain << (e.g., arithmetic shift echo $((1<<2)) or a here‑string with command substitution like python3 <<< "$(rm -rf /)") can be reduced to a simple argv prefix and matched by prefix_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 👍 / 👎.

let commands =
parse_shell_lc_plain_commands(command).unwrap_or_else(|| vec![command.to_vec()]);
let (commands, used_heredoc_fallback) = commands_for_exec_policy(command);
let auto_amendment_allowed = !used_heredoc_fallback;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @bolinfest for a bit of nuance here, but this feels reasonable to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment here so that its explicit whats happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants