The vulnerability lies in the coder config-ssh command, which writes server-supplied SSH settings to the user's ~/.ssh/config file without proper sanitization. This could allow a malicious or compromised Coder server to inject arbitrary SSH configuration, leading to remote code execution on the developer's machine.
The analysis of the patch reveals that the core of the vulnerability was the lack of input validation for the HostnameSuffix and SSHConfigOptions settings. The patch introduces validation at both the client and server sides.
On the client side, the cli.mergeSSHOptions function in cli/configssh.go is the primary vulnerable function. It is responsible for merging the server-supplied configuration with the user's local configuration. Before the patch, it directly used the values from the server without any validation. The patch adds calls to new validation functions (codersdk.ValidateWorkspaceHostnameSuffix, codersdk.ValidateSSHConfigOptions, etc.) at the beginning of this function.
On the server side, the cli.RootCmd.Server function in cli/server.go was also involved. It allowed the server to be configured with malicious SSH options that would then be sent to clients. The patch adds validation at server startup to prevent this from happening.
The codersdk.ParseSSHConfigOption function was also identified as vulnerable because it didn't properly sanitize the input, allowing newline characters that could be used to inject new SSH directives.
Therefore, during exploitation, a stack trace would likely show cli.mergeSSHOptions being called by the coder config-ssh command, processing the malicious configuration received from the server.