CVE-2024-45337
Go crypto/ssh — PublicKeyCallback Auth Bypass
Impact: Go programs implementing SSH servers via crypto/ssh.ServerConfig.PublicKeyCallback may incorrectly authenticate connections using unauthorized public keys. Affects Go < 1.22.10 and < 1.23.4. Any Gitea, custom Go SSH server, or SFTP server using this pattern is at risk.
Step-by-Step Fix Runbook
go version # Vulnerable: Go < 1.22.10 or Go < 1.23.4 # Check if you use crypto/ssh with PublicKeyCallback grep -r "PublicKeyCallback" . grep -r "crypto/ssh" go.mod go.sum # Run govulncheck for automated detection go install golang.org/x/vuln/cmd/govulncheck@latest govulncheck ./... # Will report GO-2024-3321 if vulnerable pattern found
# Download latest Go from go.dev/dl/ wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz rm -rf /usr/local/go tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz # Verify go version # Must show go1.23.4 or later # Rebuild all affected binaries after upgrading Go go build ./... # For Docker-based deployments, update base image: # FROM golang:1.23-alpine (in Dockerfile) docker build --no-cache -t myapp .
// VULNERABLE pattern — trusts callback result without additional check:
config := &ssh.ServerConfig{
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
// Bug: authentication can succeed even if this returns error in some flows
if isAllowedKey(key) {
return &ssh.Permissions{}, nil
}
return nil, fmt.Errorf("unauthorized key")
},
}
// SECURE pattern — explicit allowlist validation + post-auth check:
config := &ssh.ServerConfig{
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
keyBytes := key.Marshal()
// Explicit allowlist: reject EVERYTHING not explicitly permitted
for _, allowed := range allowedKeys {
if bytes.Equal(keyBytes, allowed.Marshal()) {
return &ssh.Permissions{
Extensions: map[string]string{"user": conn.User()},
}, nil
}
}
return nil, fmt.Errorf("key not in allowlist")
},
}# Check for authentication anomalies before patch
journalctl -u sshd --since "2024-12-01" | grep -i "accepted publickey"
# Look for unexpected successful authentications
# Especially: authentications that succeeded without expected key fingerprints
grep "Accepted publickey" /var/log/auth.log | awk '{print $9, $11}' | sort | uniq -c
# If anomalies found: rotate all SSH keys, audit what those sessions did
grep "session opened" /var/log/auth.log | tail -100# .github/workflows/security.yml
name: Go Security Scan
on: [push, pull_request]
jobs:
govulncheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Run govulncheck
run: govulncheck ./...
# Fails CI if any known vulnerable patterns detectedFrequently Asked Questions
What exactly is the CVE-2024-45337 vulnerability?
The Go crypto/ssh library has a logic flaw in how it handles PublicKeyCallback authentication. In certain code paths, when PublicKeyCallback returns an error (rejecting a key), the authentication flow may still succeed due to a race condition or logic error in the SSH handshake state machine. This means an attacker can authenticate with an unauthorized public key if the callback implementation is not written defensively. The bug affects all Go versions < 1.22.10 and < 1.23.4.
Is every Go program using crypto/ssh affected?
Only Go programs that implement an SSH server with PublicKeyCallback AND have a non-defensive callback implementation. If your PublicKeyCallback uses explicit allowlist matching (bytes.Equal comparison of serialized keys) it may be resistant. If it relies on the callback return value alone for security — it is vulnerable. Use govulncheck to automatically detect if your codebase uses the vulnerable pattern.
How do I use govulncheck to detect this?
Install: go install golang.org/x/vuln/cmd/govulncheck@latest. Run: govulncheck ./... in your project root. It will report GO-2024-3321 if it detects usage of the vulnerable crypto/ssh PublicKeyCallback pattern. govulncheck performs both binary analysis and source analysis — it will not report false positives for code paths that don't actually reach the vulnerable function.
What is the impact if exploited?
An attacker can authenticate to your Go SSH server using any public key — including keys not in your allowlist. This provides the same access as a legitimate authenticated user on your SSH server. For servers that grant shell access, this means full system compromise. For servers that use SSH for Git (like Gitea) or file transfer (SFTP), this means unauthorized access to all repositories or files.