Skip to content

vncviewer: prevent SSH option injection via -via gateway argument - #2131

Merged
CendioOssman merged 1 commit into
TigerVNC:masterfrom
acts-1631:fix-ssh-via-option-injection
Aug 6, 2026
Merged

vncviewer: prevent SSH option injection via -via gateway argument#2131
CendioOssman merged 1 commit into
TigerVNC:masterfrom
acts-1631:fix-ssh-via-option-injection

Conversation

@acts-1631

Copy link
Copy Markdown
Contributor

The via parameter (from CLI, GUI, or a loaded .vnc config file) is
passed to ssh as a bare positional argument inside createTunnel()'s
default command template. A value starting with "-" is parsed by
ssh as an option rather than a hostname, so via=-oProxyCommand=
causes ssh to run an arbitrary command through ProxyCommand.

Shell quoting of "$G" only prevents shell metacharacter/word-splitting
issues, it does not stop ssh's own option parsing from treating the
value as an option.

This inserts "--" before the expanded gateway host so ssh stops
parsing options at that point and treats the remainder strictly as
the destination, closing off the option-injection path.

Tested by setting the via value to -oProxyCommand= and
confirming the command executes before the fix and is rejected
by ssh as an invalid hostname after the fix.

@CendioOssman CendioOssman left a comment

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.

Thanks. Good find!

The -via parameter is only available via the command line, though. Which makes this less of an issue.

Could you update the commit message to reflect that?

Isn't there a potential issue with remoteHost as well?

@acts-1631
acts-1631 force-pushed the fix-ssh-via-option-injection branch from 3177ac8 to 48ef50c Compare August 5, 2026 15:21
The -via command-line parameter is passed to ssh as a bare positional argument inside createTunnel()'s default command template. A value starting with "-" is parsed by ssh as an option rather than a hostname, so -via=-oProxyCommand=<cmd> causes ssh to run an arbitrary command through ProxyCommand.

Shell quoting of "$G" only prevents shell metacharacter and word-splitting issues; it does not stop ssh from treating the value as an option.

Insert "--" before the expanded gateway host so ssh stops parsing options at that point and treats the remainder strictly as the destination, closing the option-injection path.
@acts-1631

Copy link
Copy Markdown
Contributor Author

Updated the commit message to clarify that -via is CLI-only.

I also checked remoteHost. It is embedded in the single argument to -L, so a leading - is parsed as the forwarding destination hostname, not as an SSH command-line option.

@CendioOssman

Copy link
Copy Markdown
Member

Can't you trick it into splitting the -L argument, though? E.g. if you set remoteHost to something like " -oProxyCommand=foo.

@acts-1631

Copy link
Copy Markdown
Contributor Author

I tested that payload. Since $H expands inside an already double-quoted word, quote characters in its value are not reinterpreted by the shell. It remains a single -L argument, e.g. 5000:" -oProxyCommand=foo:5900, which SSH parses as the forwarding destination rather than a command-line option.

@CendioOssman CendioOssman left a comment

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.

Great. Thanks for checking!

@CendioOssman
CendioOssman merged commit 049852b into TigerVNC:master Aug 6, 2026
16 checks passed
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.

2 participants