Repository navigation
fix: quote the remote command and validate ssh arguments - #11
Merged
Merged
Conversation
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).
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.
Summary
Closes the two injection paths in #6. Both were reproduced before the change and confirmed closed after.
--toreaching the remote shell. ssh joins everything after the destination with spaces and gives it to the remote login shell, so handingsubprocess.runan argv list protected nothing — a metacharacter in--toexecuted on the far side, and--dry-rundid not help because the injection happened before any of our code ran. The remote command is now assembled withshlex.quote.That also fixes an ordinary bug: a session named
my sessionused to resolve asmy. It now arrives intact.--host/--ssh-optreaching ssh as options. ssh has no--separator, so a leading dash turned the destination into a flag and-oProxyCommand=ran a command locally.--hostnow rejects a leading dash; both flags reject options that execute a local command (ProxyCommand,LocalCommand,PermitLocalCommand).ProxyJumpis deliberately still allowed — it takes a host, not a command, and is the right way through a bastion.Also in this change
run_remote()catchesOSError, so ssh failing to launch reports instead of raising a traceback (partial fix for Advertised 1M character cap breaks around 98K on the remote path, with a raw traceback #7)--ssh-optexample —--ssh-opt -pnever worked, argparse needs--ssh-opt=-p. Wrong since the flag was introduced; found while regression-testing this change.Verification
--towith a shell metacharacter--hoststarting with---ssh-optcarrying ProxyCommand--to 'my session'mymy sessionlist/send --dry-run/--ssh-opt=-oType
Checklist
python3 cc_peer.py listworks locallypython3 cc_peer.py list --host <a real host>works over SSH--dry-runresolves a target without posting anythingVerified 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.