The vulnerability is a critical authentication bypass in Soft Serve's SSH server. It allows an attacker to impersonate any user, including an administrator, by exploiting a flaw in how the session context was managed during public key authentication.
The attack unfolds in two stages during the SSH handshake:
- Context Poisoning: The attacker first presents the victim's public key. The vulnerable
ssh.SSHServer.PublicKeyHandler function would identify the victim as the user and store their identity in the session context. The attacker, not possessing the victim's private key, would fail the subsequent authentication challenge for this key.
- Authentication with Attacker's Key: The SSH protocol allows the client to try another key. The attacker then presents their own valid public key and successfully authenticates.
The core of the vulnerability lies in the ssh.AuthenticationMiddleware. The original version of this middleware did not re-validate the user's identity based on the key that ultimately succeeded in authenticating. It trusted the user identity already present in the context, which was the victim's from the first failed attempt. Consequently, the attacker, having authenticated with their own key, was granted the permissions and identity of the victim.
The patch rectifies this by:
- Removing the logic in
ssh.SSHServer.PublicKeyHandler that prematurely set the user in the context.
- Adding logic to
ssh.AuthenticationMiddleware to always look up the user based on the successfully authenticated public key and update the session context, ensuring the correct user identity is used for authorization.