Verify SSH host keys against known_hosts - #396
Open
jameshoweee wants to merge 1 commit into
Open
jameshoweee wants to merge 1 commit into
jameshoweee wants to merge 1 commit into
Conversation
ssh2 accepts any host key when no hostVerifier is set, so the Console completed the handshake with whatever answered the address and handed it the user's credentials and forwarded agent. Read the known_hosts files `ssh -G` resolves for the host, pin the key on first use, and refuse to connect when a pinned key changes. Honours StrictHostKeyChecking, UserKnownHostsFile, GlobalKnownHostsFile and HashKnownHosts.
jameshoweee
requested review from
amaudruz and
christian-mcdermott
as code owners
September 8, 2026 17:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ssh2 accepts any host key when no
hostVerifieris set, and the Console never sets one. So a remote connection completes against whatever answers on the address and hands it the user's password or private key, plus the forwarded agent socket when agent forwarding is on. There is no host-key check today at all.This adds one. It reads the same known_hosts files OpenSSH would use for that host (resolved from
ssh -G, so aliases andUserKnownHostsFile/GlobalKnownHostsFileare honoured), matches plain, hashed, glob and negated patterns, honours@revoked, pins the key on first use, and refuses when a pinned key changes.StrictHostKeyCheckingis respected:yesrefuses an unknown host, anything else accepts and records it. A changed key is refused under every setting. An unreadable known_hosts fails closed rather than turning into blind trust.@cert-authoritylines are reported as unknown rather than as a match. This does not validate host certificates, and ssh2 never advertises the*-cert-v01@openssh.comalgorithms, so a server cannot present one on this path anyway.Tests: 44 new cases over the parser, the matcher and the verifier, plus an end-to-end case proving the resolved ConnectConfig refuses a changed key, and one against a real known_hosts file on disk. 153/153 in the ssh suite, 3100/3101 across the node project (the one failure is session-spawner, which fails the same way on main).