fix(hook): prevent flag injection in rtk-rewrite hooks (#1350)#2475
Open
ousamabenyounes wants to merge 1 commit into
Open
fix(hook): prevent flag injection in rtk-rewrite hooks (#1350)#2475ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
ousamabenyounes
force-pushed
the
fix/issue-1350
branch
from
July 7, 2026 14:02
f862dd8 to
960dc37
Compare
Contributor
Author
|
Rebased this PR onto current |
pszymkowiak
approved these changes
Jul 9, 2026
pszymkowiak
left a comment
Collaborator
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.
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>
ousamabenyounes
force-pushed
the
fix/issue-1350
branch
from
July 16, 2026 19:17
960dc37 to
2e9c630
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.)