Terminate ssh/scp options with "--" separator by anumol-baby · Pull Request #13697 · cli/cli · GitHub
Skip to content

Terminate ssh/scp options with "--" separator#13697

Open
anumol-baby wants to merge 4 commits into
cli:trunkfrom
anumol-baby:fix/codespaces-23695
Open

Terminate ssh/scp options with "--" separator#13697
anumol-baby wants to merge 4 commits into
cli:trunkfrom
anumol-baby:fix/codespaces-23695

Conversation

@anumol-baby

@anumol-baby anumol-baby commented Jun 22, 2026

Copy link
Copy Markdown

Summary

Closes - https://github.com/github/codespaces/issues/23695
Append the POSIX end-of-options -- marker before the destination in newSSHCommand and before the file arguments in newSCPCommand (internal/codespaces/ssh.go).

-- is the standard convention to signal "stop parsing options". Adding it here guarantees that the destination/file arguments are always treated as positional, regardless of their contents, and matches common-practice hardening across other CLIs that shell out tossh/scp.

Changes

  • internal/codespaces/ssh.go — insert "--" immediately before the destination in newSSHCommand, and before the file list innewSCPCommand.
  • internal/codespaces/ssh_test.go — add tests covering both separators (TestNewSSHCommandUsesEndOfOptionsSeparator,TestNewSCPCommandUsesEndOfOptionsSeparator).

Validation

  • go test ./internal/codespaces/ passes
  • Manually confirmed ssh -- user@host and scp -- src dst behave identically to the pre-change invocations for normal inputs.

@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Jun 22, 2026
@anumol-baby anumol-baby marked this pull request as ready for review June 22, 2026 13:17
@anumol-baby anumol-baby requested review from a team as code owners June 22, 2026 13:17
@anumol-baby anumol-baby requested review from BagToad and Copilot June 22, 2026 13:17
@github-actions github-actions Bot added unmet-requirements and removed needs-triage needs to be reviewed labels Jun 22, 2026
@github-actions

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the Codespaces SSH/SCP command construction by inserting the POSIX end-of-options marker (--) so that destinations and file operands are always treated as positional arguments by ssh/scp, preventing option-injection via crafted values.

Changes:

  • Add -- before the SSH destination in newSSHCommand.
  • Add -- before SCP file operands in newSCPCommand.
  • Add unit tests asserting the separator is present and positioned correctly.
Show a summary per file
File Description
internal/codespaces/ssh.go Inserts -- into constructed ssh and scp argv to terminate option parsing before positional operands.
internal/codespaces/ssh_test.go Adds tests ensuring -- is included for both SSH and SCP command builders.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment thread internal/codespaces/ssh_test.go
Comment thread internal/codespaces/ssh_test.go
Comment thread internal/codespaces/ssh_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread internal/codespaces/ssh_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment on lines 121 to 123
cmdArgs = append(cmdArgs, connArgs...)
cmdArgs = append(cmdArgs, "--") // end of scp options

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Copilot is right. I think we should respect a user-provided --. WDYT @anumol-baby?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — addressed in latest commit. parseArgs now treats a bare -- as the end-of-options marker: it's dropped, and everything after it becomes the command, so a user-supplied -- is respected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think these new tests could just be one table test

nit: I know this file doesn't already use it, so this isn't a blocking thing, but it would be ideal if we could modernize the tests by using testify.Assert / testify.Require like the rest of the codebase. Happy to tackle that as a follow-up ourselves if no appetite for it 😁

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep this PR focused on the security fix, I'd prefer to leave the table-test consolidation (and the testify migration you mentioned) for a follow-up rather than expand the diff here. Happy to open that follow-up, or I can fold it in now if you'd rather — your call.
Thank you so much for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants