windows: the SSH tunnel's host and user cannot be read as ssh options

sshProxy.server.host and .user are ordinary settings the signed-in user
may change, and they reached ssh.exe's command line, which the service
runs as SYSTEM: a host of -oProxyCommand=<program> would have run that
program as SYSTEM (found by the commit security review). The user now
goes as -l's value and the host after "--", so neither can be an
option; the validator holds the host to a host name or IP address, the
user to a login name, and host keys to one line each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 07:41:39 +03:00
1 parent fb6c5962d0
commit 82fe4d8e65
2 files changed
+64 -6

No files matched your search

+9 -6
View File
@@ -126,11 +126,14 @@ pub fn args(cfg: &Config, known_hosts: &Path, identity: Option<&Path>) -> Vec<St
a.extend(["-i".into(), identity.display().to_string(), "-o".into(), "IdentitiesOnly=yes".into()]);
}
a.extend(s.extra_args.iter().cloned());
let host = s.server.host.clone().unwrap_or_default();
a.push(match &s.server.user {
Some(u) => format!("{u}@{host}"),
None => host,
});
// The user and the host never read as options (ssh runs as SYSTEM; `-oProxyCommand=…` as
// a host would run a program): the user as -l's value, the host after the options' end.
// The validator also holds them to a login name and a host name or address.
if let Some(u) = &s.server.user {
a.extend(["-l".into(), u.clone()]);
}
a.push("--".into());
a.push(s.server.host.clone().unwrap_or_default());
a
}
@@ -164,7 +167,7 @@ mod tests {
assert!(a.windows(2).any(|w| w == ["-p", "2222"]));
assert!(a.windows(2).any(|w| w == ["-i", r"C:\keys\id_ed25519"]));
assert!(a.contains(&"UserKnownHostsFile=kh".to_owned()));
assert_eq!(a.last().unwrap(), "me@vps.example");
assert_eq!(&a[a.len() - 4..], ["-l", "me", "--", "vps.example"]);
}
#[test]