Skip to content

fix: implement SSH host key verification to prevent MitM attacks - #42

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783046656-ssh-host-key-verification
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783046656-ssh-host-key-verification

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Replaces ssh.InsecureIgnoreHostKey() in pkg/proxy/proxy.go with a fail-closed HostKeyCallback() that supports two verification modes via environment variables:

  • SSH_KNOWN_HOSTS_FILE — path to an OpenSSH known_hosts file, verified via knownhosts.New()
  • SSH_HOST_KEY — base64-encoded raw public key for pinning (e.g. from ssh-keyscan | awk '{print $3}')

If neither is set, DialThroughBoundary returns an error — no silent fallback to insecure mode.

// before
HostKeyCallback: ssh.InsecureIgnoreHostKey(),

// after
hostKeyCb, err := HostKeyCallback() // reads SSH_KNOWN_HOSTS_FILE or SSH_HOST_KEY
// ...
HostKeyCallback: hostKeyCb,

New file pkg/proxy/hostkey.go contains HostKeyCallback(), ErrHostKeyMismatch, and the pinned/known_hosts callbacks.

Tests added in main_test.go:

  • TestHostKeyMismatch — pins wrong key, asserts ErrHostKeyMismatch
  • TestHostKeyMatch — pins correct key, asserts successful connection
  • TestHostKeyCallback_NeitherConfigured — asserts error when unconfigured
  • TestHostKeyCallback_KnownHostsFile — writes a temp known_hosts, verifies acceptance

Fixes #13

Link to Devin session: https://app.devin.ai/sessions/2a885a94e7464a9993c6f40865502ea9

Add HostKeyCallback() in pkg/proxy that supports two verification modes:
- SSH_KNOWN_HOSTS_FILE: OpenSSH known_hosts file verification
- SSH_HOST_KEY: base64-encoded pinned public key verification

Fail-closed: if neither env var is set, connections are rejected.

Add tests for host key mismatch, match, known_hosts, and unconfigured cases.

Co-Authored-By: bot_apk <apk@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Implement SSH Host Key Verification

0 participants