Skip to content

fix: quote the remote command and validate ssh arguments - #11

Merged
abruption merged 1 commit into
mainfrom
fix/6-command-injection
Sep 7, 2026
Merged

abruption merged 1 commit into
mainfrom
fix/6-command-injection

Conversation

@abruption

Copy link
Copy Markdown
Owner

Summary

Closes the two injection paths in #6. Both were reproduced before the change and confirmed closed after.

--to reaching the remote shell. ssh joins everything after the destination with spaces and gives it to the remote login shell, so handing subprocess.run an argv list protected nothing — a metacharacter in --to executed on the far side, and --dry-run did not help because the injection happened before any of our code ran. The remote command is now assembled with shlex.quote.

That also fixes an ordinary bug: a session named my session used to resolve as my. It now arrives intact.

--host / --ssh-opt reaching ssh as options. ssh has no -- separator, so a leading dash turned the destination into a flag and -oProxyCommand= ran a command locally. --host now rejects a leading dash; both flags reject options that execute a local command (ProxyCommand, LocalCommand, PermitLocalCommand). ProxyJump is deliberately still allowed — it takes a host, not a command, and is the right way through a bastion.

Also in this change

Verification

before after
--to with a shell metacharacter marker executed on the remote treated as a session name, no execution
--host starting with - ProxyCommand ran locally rejected with a reason
--ssh-opt carrying ProxyCommand ProxyCommand ran locally rejected with a reason
--to 'my session' resolved as my resolved as my session
normal list / send --dry-run / --ssh-opt=-o works works

Type

  • feat
  • fix
  • docs
  • chore / refactor / test / perf

Checklist

  • python3 cc_peer.py list works locally
  • python3 cc_peer.py list --host <a real host> works over SSH
  • --dry-run resolves a target without posting anything
  • Commits follow Conventional Commits
  • Docs updated if behavior changed (README / SKILL.md / CLAUDE.md)
  • No secrets, tokens, or session keys in the diff

Verified against

v2.1.263 — macOS 26 (arm64) → Ubuntu 24.04 (arm64), both KR and US hosts.

Notes

Found by a peer Claude Code session reviewing the repo, and re-reproduced here independently before fixing. Remaining items from that review are #7, #8, #9, #10.

Two injection paths, both reproduced before and after.

ssh joins everything after the destination with spaces and hands it to the
remote login shell, so passing an argv list was not the protection it looked
like — a metacharacter in --to executed on the far side, and --dry-run did
not stop it because the injection happened in the ssh layer. The remote
command is now built with shlex.quote, which also fixes session names
containing spaces resolving to their first word.

ssh has no -- separator, so a --host beginning with a dash was parsed as an
option; -oProxyCommand= then ran a command locally. --host now rejects a
leading dash, and both --host and --ssh-opt reject options that execute a
local command. ProxyJump is deliberately still allowed: it takes a host, not
a command, and is how you reach a box behind a bastion.

Also catches OSError around subprocess so ssh failing to launch reports
rather than tracebacks, and corrects a README example — argparse cannot take
"--ssh-opt -p", it needs "--ssh-opt=-p" (wrong since the flag was added).
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.

1 participant