Skip to content

fix(proxy): reject shell snippets in single-arg form (#2163)#2165

Open
pen-pal wants to merge 1 commit into
rtk-ai:developfrom
pen-pal:fix/proxy-reject-shell-snippets-2163
Open

fix(proxy): reject shell snippets in single-arg form (#2163)#2165
pen-pal wants to merge 1 commit into
rtk-ai:developfrom
pen-pal:fix/proxy-reject-shell-snippets-2163

Conversation

@pen-pal
Copy link
Copy Markdown

@pen-pal pen-pal commented May 30, 2026

Summary

  • Reject shell snippets in rtk proxy single-arg form.
  • Bail on unquoted ;, &&, |, $(), >, <, &, `, (, {, newline. Quoted metachars stay literal.
  • Error points users to rtk proxy sh -c '…' for shell semantics.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test - 1986 pass, 0 warn
  • 4 new unit tests
  • Manual: repro rejected; 'echo hello', 'git log --format="%H %s" -1', multi-arg form still run; | and $() rejected

Closes #2163

`rtk proxy` executes the target binary directly via `Command::spawn`,
with no shell in between. When a user wrapped a compound shell snippet
in a single quoted argument (`rtk proxy 'for i in 1 2; do echo $i; done'`),
`shell_split` produced tokens like `["for", "i", "in", "1", "2;", ...]`
and operators (`;`, `&&`, `|`, `$()`, `>`, `&`) silently became
positional arguments to the first binary. Worst case: token-like
fragments created unintended filesystem entries.

Add `first_unquoted_shell_metachar` that walks the raw single-arg
string with the same quote state machine as `shell_split`, returning
the first metacharacter that sits outside `'…'` / `"…"`. The proxy
single-arg branch consults it before invoking `shell_split` and bails
with a clear error message pointing at `rtk proxy sh -c '…'` for users
who genuinely want shell semantics.

Quoted operators stay legitimate payloads (`--format="%H %s"`, commit
messages containing `&&`, etc.) — only unquoted metachars trip the
rejection. Multi-arg form (`rtk proxy git log -1`) is unaffected
since it never goes through `shell_split`.

Covered by four new unit tests in `tests`:
- simple commands accepted
- quoted metacharacters ignored
- bare operators (`;`, `|`, `&&`, `>`, `<`, `$(`, backtick, `(`) rejected
- the issue rtk-ai#2163 compound-loop reproducer rejected

Signed-off-by: penpal <unameme@proton.me>
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.

rtk proxy should reject or safely handle compound shell snippets

1 participant