Repository navigation
fix(hooks): emit permissionDecision allow for simple Copilot CLI rewrites - #3149
Conversation
…ites Copilot CLI 1.0.66+ treats a missing permissionDecision field as "always prompt", forcing a permission dialog on every RTK-rewritten command. For simple (non-compound) commands, emit permissionDecision: "allow" so Copilot auto-accepts the rewrite. Compound commands (containing newlines, background &, subshells, or pipes) still omit the field, preserving the security guarantee that hidden dangerous segments trigger a manual prompt. Uses split_for_permissions() to detect compound commands — if the command decomposes into more than one segment, it's not safe to auto-allow. Closes rtk-ai#3037 Co-Authored-By: Claude Opus 4.6 <[email protected]>
pszymkowiak
left a comment
There was a problem hiding this comment.
Verified on a compiled build, both unit and end-to-end. The security boundary (split_for_permissions(cmd).len() <= 1) holds — I drove the real rtk hook copilot with Copilot-CLI-shaped JSON on stdin:
cargo test / git status → {"modifiedArgs":{"command":"rtk cargo test"},"permissionDecision":"allow"}
git status && git push → {"modifiedArgs":{...}} (no permissionDecision → Copilot prompts)
cargo test; rm -rf x → {"modifiedArgs":{...}} (no allow — the rm -rf isn't auto-approved) ✓
cargo test $(rm -rf /tmp/x) → (no response → defer)
cargo test && echo hi > /etc/passwd → (no response → defer)
So only simple, single-segment rewrites get allow; anything compound or dangerous keeps Copilot's own prompt, and substitution/redirect forms defer entirely. Also confirmed decide_from_verdict handles Deny before AskRewrite, so this never auto-allows a denied command. 44 copilot/hook tests pass, including the CVE ones (newline_bypass/background_bypass never auto-allow).
One semantic note (non-blocking): AskRewrite maps to verdict Ask, which covers both the default (no rule) and an explicit user ask rule — so a simple rewritable command a user explicitly marked "ask" would now auto-allow under Copilot. Given this is scoped to Copilot CLI's 1.0.66 behavior, rtk only rewrites a curated command set, and the verdict doesn't expose default-vs-explicit, it's a reasonable trade-off — maybe worth a line in the docs.
LGTM 👍
Change AskRewrite(String) to AskRewrite { rewritten, explicit } so the
Copilot path only auto-allows when the user didn't explicitly configure
"ask" for a command. Addresses KuSh's review feedback on rtk-ai#3149.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Heyaaa! : )
I've been testing RTK with Copilot CLI and since version 1.0.66, every rewrite triggers a permission prompt — even safe stuff like
cargo test→rtk cargo test. Copilot changed how it handles missingpermissionDecision: now treats it as "always ask." SinceAskRewriteomitted the field, every rewrite became manual approval.Fix: emit
permissionDecision: "allow"for simple single-segment commands. Compound commands (newlines,&,;, pipes) still omit it so Copilot shows its own prompt. Uses existingsplit_for_permissions()— all CVE bypass security tests still pass.Closes #3037
Test plan
cargo test) now getpermissionDecision: "allow"git status\nrm -rf /) still omitpermissionDecisioncargo test --all)cargo fmt --all && cargo clippy --all-targetsclean