fix(ssh): linear host-pattern matching, per-hop forwarding gates, loopback remote forwards
- known_hosts: the @cert-authority pattern matcher was recursive and backtracking; a pattern of a few hundred thousand stars overflowed the connect thread's stack on every handshake and '*a*a*a…b' went exponential. It is now the iterative two-pointer match, and patterns over 1 KiB are refused on import and in Trust a CA. - Agent-forward and remote-forward channels are only honoured on the final hop: a jump host could previously open auth-agent channels and reach remote-forward destinations on the client machine. - Remote forwards with no bind address listen on the server's loopback (as ssh -R does) instead of every interface. - Keyboard-interactive gives up after 10 rounds; dials through jump hosts and run_command have timeouts; the handshake timeout leaves room for the host-key prompt so a slow reader isn't timed out mid-decision. - Known hosts are looked up per key type, so an imported known_hosts with ed25519 and RSA rows no longer produces a false 'key changed' warning. - SFTP download suggests a sanitised base name in the save dialog.
This commit is contained in:
@@ -324,7 +324,7 @@ impl Service {
|
||||
/// Trusts an SSH certificate authority for hosts matching `pattern` (OpenSSH syntax).
|
||||
pub fn add_cert_authority(&self, pattern: &str, public_key: &str) -> Result<()> {
|
||||
let pattern = pattern.trim();
|
||||
if pattern.is_empty() || pattern.contains(char::is_whitespace) {
|
||||
if pattern.is_empty() || pattern.contains(char::is_whitespace) || pattern.len() > crate::known_hosts::MAX_PATTERN_LEN {
|
||||
return Err("the host pattern must be one word, e.g. *.example.com".into());
|
||||
}
|
||||
let key = russh::keys::PublicKey::from_openssh(public_key.trim()).map_err(|e| format!("not an OpenSSH public key: {e}"))?;
|
||||
|
||||
Reference in New Issue
Block a user