Skip to content

fix: verify server host keys in the ssh client builtin (3.x backport) - #2237

Merged
gnodet merged 3 commits into
jline-3.xfrom
backport/3.x/ssh-host-key-verification
Sep 8, 2026
Merged

gnodet merged 3 commits into
jline-3.xfrom
backport/3.x/ssh-host-key-verification

Conversation

@gnodet

@gnodet gnodet commented Sep 7, 2026

Copy link
Copy Markdown
Member

Backport of #2236 to jline-3.x.

The ssh builtin's default client accepts any server host key, so a swapped endpoint silently captures the credentials the user types. This installs an OpenSSH-style known_hosts verifier when the client is still on the accept-all default: match recorded keys, confirm and record unknown keys, refuse changed keys.

Cherry-picked cleanly from 47e16bf.

* fix: verify server host keys in the ssh client builtin

The ssh builtin's default client accepts any server host key, so a
swapped endpoint silently captures the credentials the user types.
Install an OpenSSH-style known_hosts verifier when the client is still
on the accept-all default: match recorded keys, confirm and record
unknown keys, refuse changed keys.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5Bf8mxp6ZPnsCBBC45Hx2

* fix: track verifier installation and create known_hosts parent dir

- Use a client property to track whether setupServerKeyVerifier installed
  the KnownHostsServerKeyVerifier, so an AcceptAllServerKeyVerifier.INSTANCE
  explicitly set by the caller after our install is not replaced on
  subsequent calls.
- Create the ~/.ssh parent directory (if missing) before constructing
  the KnownHostsServerKeyVerifier to prevent failures when the path
  does not exist yet.
- Extend callerConfiguredVerifierIsLeftInPlace to verify the
  AcceptAllServerKeyVerifier.INSTANCE tracking.
- Add regression test with tempDir.resolve("missing/.ssh/known_hosts")
  that verifies the directory is created and the confirmed host key is
  persisted.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
@gnodet gnodet added the bug label Sep 7, 2026
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: e3353b2e-5f12-4489-8e10-c24f9e49fd65

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

@gnodet
gnodet merged commit 2b1cff8 into jline-3.x Sep 8, 2026
13 checks passed
@gnodet
gnodet deleted the backport/3.x/ssh-host-key-verification branch September 8, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants