Skip to content

Insecure SSH Connection

Description

The application ignores host keys, which provide assurance that the client can prove the host is trusted. By ignoring these host keys, it is impossible for the client to validate the connection is to a trusted host.

Examples

Insecure Code

go
ssh.InsecureIgnoreHostKey(...)

Secure Code

go
knownHostCallback, err := knownhosts.New("/home/user/.ssh/known_hosts")
config := &ssh.ClientConfig{
  ...
  HostKeyCallback: knownHostCallback,
}

Remediation

Use the knownhosts package to parse OpenSSH's known_hosts key database for the ssh.ClientConfig HostKeyCallback property.

Rule Details

FieldValue
IDCODE-0776
CategoryAuth
SeverityMEDIUM
CWECWE-322
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsssh, authentication, known_hosts
OWASPA2:2017-Broken Authentication, A07:2021-Identification and Authentication Failures