CVE-2024-45337: Misuse of ServerConfig.PublicKeyCallback may cause authorization bypass in golang.org/x/crypto
9.1
Basic Information
Technical Details
Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
---|---|---|---|
golang.org/x/crypto | go | < 0.31.0 | 0.31.0 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability CVE-2024-45337 concerns a potential authorization bypass in applications misusing ServerConfig.PublicKeyCallback
in golang.org/x/crypto/ssh
. The core issue is that the callback might be invoked with multiple keys, and applications might incorrectly assume the last key seen by the callback is the one used for authentication. The provided patch (commit b4f1988a35dee11ec3e05d6bf3e90b695fbd8909) addresses this by modifying the public key caching mechanism within the SSH server implementation.
The primary change in the patch is to the ssh/server.go
file, specifically:
- The constant
maxCachedPubKeys
is reduced from16
to1
. - The
(*pubKeyCache).add
method is modified to implement a strict FIFO (First-In, First-Out) behavior for this cache of size 1.
The function (*pubKeyCache).add
is directly involved in managing the state that could lead to the vulnerability. Its previous behavior (allowing a larger cache that wasn't necessarily ordered by authentication success) contributed to the possibility of the user's PublicKeyCallback
being misled about which key was ultimately used for authentication. By changing (*pubKeyCache).add
to maintain only the single most recent key, the library now enforces that the last call to PublicKeyCallback
(in a successful public key authentication scenario) corresponds to the authenticated key. Therefore, (*pubKeyCache).add
is identified as a key function related to the vulnerability because its previous implementation was part of the mechanism that allowed the confusing state, and its modification is central to the mitigation.