You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Host key comparisons in paramiko/hostkeys.py and paramiko/transport.py use Python's == and != operators, which short-circuit on the first mismatched byte. This creates a timing side channel that could allow an attacker to infer the correct host key byte-by-byte.
Code Locations
paramiko/hostkeys.py line ~224:
returnhost_key.asbytes() ==key.asbytes()
paramiko/transport.py line ~1423:
orkey.asbytes() !=hostkey.asbytes()
Context
Paramiko already has a constant-time comparison utility (paramiko.util.constant_time_bytes_eq) and uses it for hashed hostname matching in hostkeys.py line ~203 (_hostname_matches). However, the actual host key bytes comparison does not use it.
Suggested Fix
# hostkeys.py line ~224returnconstant_time_bytes_eq(host_key.asbytes(), key.asbytes())
# transport.py line ~1423ornotconstant_time_bytes_eq(key.asbytes(), hostkey.asbytes())
Impact
An attacker with network position could use timing measurements across many connections to determine bytes of the expected host key. Exploitation requires many measurements and network control, so severity is Medium.
Environment
Observed on latest main branch
constant_time_bytes_eq already exists in paramiko.util
Activity