Skip to content

fix: stop version-flag scan at the remote command boundary#7

Merged
jamiesun merged 1 commit into
mainfrom
fix/version-flag-scan-positional
Jun 9, 2026
Merged

fix: stop version-flag scan at the remote command boundary#7
jamiesun merged 1 commit into
mainfrom
fix/version-flag-scan-positional

Conversation

@jamiesun

@jamiesun jamiesun commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up hardening found during an overall review of the version/skill work.

handleVersionFlag scanned every argument for --version/-v/-V. Because a remote command is the trailing argument, a bare -v token in an unquoted command (e.g. sshx -h=host grep -v foo) was mistaken for a version request — sshx printed the version and exited 0 instead of running the command. This is misleading for scripts/agents (an unexpected exit 0).

Fix

Stop the scan at the first positional argument, so only a version flag that appears before the remote command is honored.

  • sshx --version / -v / -V ✓ (unchanged)
  • sshx -h=host --version ✓ (flags only, still prints)
  • sshx -h=host grep -v foo → now runs the command (the -v is no longer hijacked)

Adds a table test (cmd/sshx/main_test.go) covering recognized vs. ignored cases, and a CHANGELOG note.

Verification

  • gofmt/go vet clean; go test ./... passes (new TestHandleVersionFlag included).
  • Manual probe with -ldflags -X main.Version=test123 confirms all four cases above.

handleVersionFlag scanned every argument, so a bare -v/-V/--version token
inside an unquoted remote command (e.g. `sshx -h=host grep -v foo`) was
mistaken for a version request and printed the version with exit 0 instead
of running the command. Stop the scan at the first positional argument so
only a version flag that precedes the command is honored, and add a table
test covering the recognized and ignored cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jamiesun jamiesun force-pushed the fix/version-flag-scan-positional branch from 1b413e9 to bddec0a Compare June 9, 2026 17:16
@jamiesun jamiesun merged commit f10189b into main Jun 9, 2026
6 checks passed
@jamiesun jamiesun deleted the fix/version-flag-scan-positional branch June 9, 2026 17:18
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