VYPR
Critical severity9.1NVD Advisory· Published Dec 12, 2024· Updated Apr 15, 2026

CVE-2024-45337

CVE-2024-45337

Description

Applications and libraries which misuse connection.serverAuthenticate (via callback field ServerConfig.PublicKeyCallback) may be susceptible to an authorization bypass. The documentation for ServerConfig.PublicKeyCallback says that "A call to this function does not guarantee that the key offered is in fact used to authenticate." Specifically, the SSH protocol allows clients to inquire about whether a public key is acceptable before proving control of the corresponding private key. PublicKeyCallback may be called with multiple keys, and the order in which the keys were provided cannot be used to infer which key the client successfully authenticated with, if any. Some applications, which store the key(s) passed to PublicKeyCallback (or derived information) and make security relevant determinations based on it once the connection is established, may make incorrect assumptions. For example, an attacker may send public keys A and B, and then authenticate with A. PublicKeyCallback would be called only twice, first with A and then with B. A vulnerable application may then make authorization decisions based on key B for which the attacker does not actually control the private key. Since this API is widely misused, as a partial mitigation golang.org/x/cry...@v0.31.0 enforces the property that, when successfully authenticating via public key, the last key passed to ServerConfig.PublicKeyCallback will be the key used to authenticate the connection. PublicKeyCallback will now be called multiple times with the same key, if necessary. Note that the client may still not control the last key passed to PublicKeyCallback if the connection is then authenticated with a different method, such as PasswordCallback, KeyboardInteractiveCallback, or NoClientAuth. Users should be using the Extensions field of the Permissions return value from the various authentication callbacks to record data associated with the authentication attempt instead of referencing external state. Once the connection is established the state corresponding to the successful authentication attempt can be retrieved via the ServerConn.Permissions field. Note that some third-party libraries misuse the Permissions type by sharing it across authentication attempts; users of third-party libraries should refer to the relevant projects for guidance.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
golang.org/x/cryptoGo
< 0.31.00.31.0

Patches

1
b4f1988a35de

ssh: make the public key cache a 1-entry FIFO cache

https://github.com/golang/cryptoRoland ShoemakerDec 3, 2024via ghsa
2 files changed · +60 4
  • ssh/server.go+11 4 modified
    @@ -149,15 +149,21 @@ func (s *ServerConfig) AddHostKey(key Signer) {
     }
     
     // cachedPubKey contains the results of querying whether a public key is
    -// acceptable for a user.
    +// acceptable for a user. This is a FIFO cache.
     type cachedPubKey struct {
     	user       string
     	pubKeyData []byte
     	result     error
     	perms      *Permissions
     }
     
    -const maxCachedPubKeys = 16
    +// maxCachedPubKeys is the number of cache entries we store.
    +//
    +// Due to consistent misuse of the PublicKeyCallback API, we have reduced this
    +// to 1, such that the only key in the cache is the most recently seen one. This
    +// forces the behavior that the last call to PublicKeyCallback will always be
    +// with the key that is used for authentication.
    +const maxCachedPubKeys = 1
     
     // pubKeyCache caches tests for public keys.  Since SSH clients
     // will query whether a public key is acceptable before attempting to
    @@ -179,9 +185,10 @@ func (c *pubKeyCache) get(user string, pubKeyData []byte) (cachedPubKey, bool) {
     
     // add adds the given tuple to the cache.
     func (c *pubKeyCache) add(candidate cachedPubKey) {
    -	if len(c.keys) < maxCachedPubKeys {
    -		c.keys = append(c.keys, candidate)
    +	if len(c.keys) >= maxCachedPubKeys {
    +		c.keys = c.keys[1:]
     	}
    +	c.keys = append(c.keys, candidate)
     }
     
     // ServerConn is an authenticated SSH connection, as seen from the
    
  • ssh/server_test.go+49 0 modified
    @@ -5,6 +5,7 @@
     package ssh
     
     import (
    +	"bytes"
     	"errors"
     	"fmt"
     	"io"
    @@ -299,6 +300,54 @@ func TestBannerError(t *testing.T) {
     	}
     }
     
    +func TestPublicKeyCallbackLastSeen(t *testing.T) {
    +	var lastSeenKey PublicKey
    +
    +	c1, c2, err := netPipe()
    +	if err != nil {
    +		t.Fatalf("netPipe: %v", err)
    +	}
    +	defer c1.Close()
    +	defer c2.Close()
    +	serverConf := &ServerConfig{
    +		PublicKeyCallback: func(conn ConnMetadata, key PublicKey) (*Permissions, error) {
    +			lastSeenKey = key
    +			fmt.Printf("seen %#v\n", key)
    +			if _, ok := key.(*dsaPublicKey); !ok {
    +				return nil, errors.New("nope")
    +			}
    +			return nil, nil
    +		},
    +	}
    +	serverConf.AddHostKey(testSigners["ecdsap256"])
    +
    +	done := make(chan struct{})
    +	go func() {
    +		defer close(done)
    +		NewServerConn(c1, serverConf)
    +	}()
    +
    +	clientConf := ClientConfig{
    +		User: "user",
    +		Auth: []AuthMethod{
    +			PublicKeys(testSigners["rsa"], testSigners["dsa"], testSigners["ed25519"]),
    +		},
    +		HostKeyCallback: InsecureIgnoreHostKey(),
    +	}
    +
    +	_, _, _, err = NewClientConn(c2, "", &clientConf)
    +	if err != nil {
    +		t.Fatal(err)
    +	}
    +	<-done
    +
    +	expectedPublicKey := testSigners["dsa"].PublicKey().Marshal()
    +	lastSeenMarshalled := lastSeenKey.Marshal()
    +	if !bytes.Equal(lastSeenMarshalled, expectedPublicKey) {
    +		t.Errorf("unexpected key: got %#v, want %#v", lastSeenKey, testSigners["dsa"].PublicKey())
    +	}
    +}
    +
     type markerConn struct {
     	closed uint32
     	used   uint32
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

10

News mentions

0

No linked articles in our index yet.