Repository navigation
fix(hook): gate reads the rewrite's own wrapper scan; assignment redirects and continuation joins match bash - #4554
Conversation
…rects and continuation joins match bash Closes the three gaps rtk-ai#4530 left open (rtk-ai#4545): - The permission gate now asks when the rewrite reaches a wrapper behind a transparent prefix and changes its script inside. Previously only a wrapper at the segment start refused the outer auto-allow, so 'env bash -c "git status"' rode an 'env:*' allow (exit 0) on a line RTK had rewritten. The gate reads the rewrite's own wrapper handling (rewrite_shell_wrapper at the positions shell_wrapper_positions yields) instead of re-deriving reach, so the two cannot drift. rtk-ai#4530's Defer-not-Deny semantics on a denied inner script are kept. - split_for_permissions no longer truncates a segment at a redirect glued to an assignment prefix: bash attaches 'FOO=a>/dev/null' to the assignment's null command and the words after it are the command, so the gate now sees and denies the 'git push' that follows instead of gating on 'FOO=a' alone. - collapse_line_continuations removes '\<NL>' the way bash does, joining the bytes either side with nothing. The old space-join rewrote 'sh -c "rm\<NL>-rf x"' as 'sh -c "rm -rf x"' — a different command — and hid 'git p\<NL>ush' (bash: 'git push') from deny rules. Wrappers the rewrite cannot rewrite inside ('bash -lc', unrewritable scripts, pipeline stages the rewrite preserves) keep the outer verdict. Submitted with AI assistance (Claude, Anthropic) as part of an open-source contribution exercise.
src/hooks/README.md still said a wrapper behind a prefix 'is only checked for deny rules and otherwise keeps the outer command's verdict, as on master' — exactly the behavior rtk-ai#4545 changed. Now: a reached wrapper whose script the rewrite changes inside is asked (the gate reads registry::wrapper_script_changed_by_rewrite), a wrapper the rewrite parses but leaves unchanged keeps the outer verdict, and a denied inner script still defers (exit 1).
📊 Automated PR Analysis
SummaryFixes three gaps in rtk's permission-gate hook left open by PR #4530: the gate now reads the rewrite's own wrapper-scan positions instead of re-deriving reach, so wrappers behind transparent prefixes (e.g. Review Checklist
Linked issues: #4545 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
Thanks for the contribution! Before we can review and merge this, the CLA needs to be signed. The CLAassistant bot left the link above, it only takes a minute. Once it's signed we'll pick the review up. |
|
Just signed the CLA via the cla-assistant.io link — the badge may take a moment to refresh. Happy to proceed with the review whenever you get a chance, and let me know if anything needs changing. |
Summary
Root cause
check_shell_wrapper_permissionsonly setcontains_shell_wrapperatdepth == 0, so a wrapper behind a transparent prefix was gated by the outer rule alone:env bash -c 'git status'rode anenv:*allow (exit 0) on a line RTK had rewritten.split_segmentscounted an assignment word as command text, so the segment was cut at the redirect inFOO=a>/dev/null git pushand the gate sawFOO=awhile the rewriter swallowed the whole prefix and emittedrtk git push.registry::collapse_line_continuationsjoined\⏎with a space where bash deletes it, rewritinggit p\⏎ushinto a different command and hiding it from deny rules.Fix
depth >= 1the gate callsregistry::wrapper_script_changed_by_rewrite, which replays the rewrite's ownrewrite_shell_wrapperat the positionsshell_wrapper_positionsyields — it reads what the rewrite did rather than re-deriving reach, so gate and rewrite cannot drift by construction. If the rewrite changed the wrapper's script inside, the verdict isAsk. fix(hook): defer on a denied command inside a prefixed shell wrapper #4530's Defer-not-Deny on a denied inner script is kept, and wrappers the rewrite cannot rewrite inside (bash -lc, unrewritable scripts, pipeline stages the rewrite preserves) keep the outer verdict.collapse_line_continuationsnow removes\⏎(bash semantics) viaBASH_JOIN_RE.Notes
env bash -c 'git reset --hard'underask git reset:*) shows 0 in its ffa5651 baseline column; on ffa5651 it is actually 1 —git reset --hardis not rewritten at all, so no gate question can surface. The gate's verdict moves Allow → Ask, thertk rewriteexit code stays 1. Recorded as found.--print-outcomeflag does not exist in the CLI; verification below uses the realrtk rewritecontract (exit 0 allow-covering rewrite · 1 no rewrite · 2 deny · 3 ask) as documented insrc/main.rs.cargo testwith several filter words needscargo test --quiet -- lexer registry(the words are independent substring filters after--).allow Bash(*)+deny Bash(git push:*)unless noted (rtk rewriteexit: 0 · 1 · 2 · 3)env bash -c 'git status'env bash -c "rtk git status"env bash -c 'git -C . push'env bash -c "rtk git -C . push"FOO=a>/dev/null git pushenv bash -c 'git push'(allow Bash(env:*)+ deny)env bash -c "git c\⏎heckout -b x"(allow Bash(env:*)+ deny)env bash -c "rtk git checkout -b x"env bash -c 'git reset --hard'(allow Bash(env:*)+ask git reset:*)Test plan
timeout 300 cargo test --quiet -- lexer registry→ 616 passed / 0 failed (acceptance red run before the fix: 613 / 3, the three new tests);timeout 300 cargo test --quiet -- permissions→ 135 passed / 0 failed (red: 131 / 3);timeout 600 cargo test --quiet→ 4397 passed / 0 failed over 36 targetscargo fmt --all --checkclean;cargo clippy --all-targets0 warningssettings.json,HOMEandCLAUDE_CONFIG_DIRboth pinned to the fixture directory so no real agent config leaks in; baseline column from the acceptance runs on ffa5651🤖 Generated with Claude Code