Repository navigation
fix(hook): prevent flag injection in rtk-rewrite hooks (#1350) - #2475
ousamabenyounes wants to merge 1 commit into
Conversation
f862dd8 to
960dc37
Compare
|
Rebased this PR onto current |
pszymkowiak
left a comment
There was a problem hiding this comment.
Reproduced the bug live, and re-tested with real usage after the fix — no regressions (git status, git log -10, cargo test --release, chained commands, ls -al all rewrite identically to before). Hook shell test suite passes 5/5 on the flag-injection cases. cargo fmt, cargo clippy --all-targets, cargo test --all all clean.
960dc37 to
2e9c630
Compare
Adopt upstream rtk-ai#2475: hook - prevent flag injection in rtk-rewrite hooks
2e9c630 to
e8124ea
Compare
Before this change, the Claude and Cursor rewrite hooks called `rtk rewrite "$CMD"` without a `--` terminator. An LLM-generated command starting with `-`/`--` (e.g. "--help") would be intercepted by clap as a flag to the `rewrite` subcommand, causing the help text to be emitted as the "rewritten" command and fed back to the agent, which would then shell-execute the help-text content. Adding `--` makes clap treat `$CMD` as a positional argument so no flag-injection is possible. New tests exercise `--help`, `-h`, `--version`, and `-V` at both the CLI parser level (Rust) and the hook level (bash). Co-Authored-By: Claude <noreply@anthropic.com>
e8124ea to
30cf832
Compare
|
Hi @aeppling 👋 — this one is approved by @pszymkowiak, freshly rebased on |
|
Hi @ousamabenyounes, As noted in the related issue, $ rtk rewrite -- -h || echo "ERROR"
ERROR
$ rtk rewrite -- --help || echo "ERROR"
ERROR
$ rtk rewrite -- -V || echo "ERROR"
ERROR
$ rtk rewrite -- --version || echo "ERROR"
ERROR
$ rtk rewrite -- -- || echo "ERROR"
ERRORSo this PR can be safely closed. |
|
happy to contribute on RTk! thank for this feedback |
Fixes #1350.
The Claude/Cursor rewrite hooks called
rtk rewrite "$CMD"without a--terminator. When a user command begins with a hyphen (--help,-h), clap interprets it as a flag to therewritesubcommand: it prints help/usage text and exits 0. The hook then feeds that help text back to the agent as the "rewritten" command, which is shell-executed — a flag-injection footgun.Fix
--terminator:rtk rewrite -- "$CMD"in bothhooks/claude/rtk-rewrite.shandhooks/cursor/rtk-rewrite.sh, so hyphen-prefixed input is always captured as a positional arg.rtk rewrite -- <flagish>parses the input as a positional rather than triggering clap's built-in help/version paths.--help,-h,--version,-V, and lone--.Test verification (RED → GREEN)
RED - prod fix reverted (
rtk rewrite "$CMD"),hooks/claude/test-rtk-rewrite.shsection 5b:GREEN - with the
--terminator, after rebasing onto currentdevelop:Rust targeted regression:
Full local gate after rebase:
(Re-proposes the work from the accidentally-closed #1370, rebased onto current
develop.)