VAITP Dataset

← Back to the dataset

CVE-2026-45309

AsyncSSH path traversal in %u expansion allows auth with attacker-chosen key.

  • CVSS 8.2
  • CWE-22
  • Input Validation and Sanitization
  • Remote

AsyncSSH is a Python package which provides an asynchronous client and server implementation of the SSHv2 protocol on top of the Python asyncio framework. Prior to 2.23.0, AsyncSSH expands the OpenSSH-compatible AuthorizedKeysFile %u token in asyncssh/config.py, asyncssh/connection.py, asyncssh/auth_keys.py, and asyncssh/misc.py with the raw SSH username during pre-authentication server config reload, allowing a server configured with AuthorizedKeysFile authorized_keys/%u to read an authorized-keys file outside the intended directory when the SSH username contains /, \, or .. path traversal segments and authenticate with an attacker-selected key file. This issue is fixed in version 2.23.0.

CVSS base score
8.2
Published
2026-07-17
OWASP
A01 Broken Access Control
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
AsyncSSH
Fixed by upgrading
Yes

Solution

Upgrade AsyncSSH to version 2.23.0 or later.

Vulnerable code sample

import os

def expand_authorized_keys_path(path_template, username):
    """
    This function represents the vulnerable logic from AsyncSSH versions
    prior to the fix for CVE-2026-45309.

    It performs a direct, unsanitized string replacement for the '%u' token,
    which allows a malicious username containing path traversal characters
    ('..', '/', '\') to cause the server to read a file from an
    unintended location.
    """
    # The core of the vulnerability is this direct replacement without sanitation.
    return path_template.replace('%u', username)

# --- Demonstration of the vulnerability in a server context ---

# 1. A server is configured with 'AuthorizedKeysFile' using the %u token.
#    The intent is to scope key files to a specific directory.
server_config_path = 'authorized_keys/%u'

# 2. An attacker provides a malicious username during the SSH handshake.
#    This username is crafted to traverse the filesystem.
malicious_username = '../root/.ssh/authorized_keys'

# 3. The server-side code uses the vulnerable function to determine which
#    authorized_keys file to read for authentication.
resolved_path = expand_authorized_keys_path(server_config_path, malicious_username)

# 4. The resulting path points outside the intended 'authorized_keys/' directory.
#    This would cause the server to attempt to read the root user's authorized_keys
#    file, allowing the attacker to authenticate if they control the key within it.
print(f"Configuration: AuthorizedKeysFile {server_config_path}")
print(f"Malicious Username: '{malicious_username}'")
print(f"Resulting Path to Read: '{resolved_path}'")

# For comparison, a legitimate user 'testuser' would resolve correctly:
legitimate_username = 'testuser'
legitimate_path = expand_authorized_keys_path(server_config_path, legitimate_username)
print(f"\nLegitimate Path for user '{legitimate_username}': '{legitimate_path}'")

Patched code sample

def _sanitize_path_segment(path_segment: str) -> str:
    """Sanitize a path segment to remove path traversal characters."""

    return path_segment.replace('/', '').replace('\\', '').replace('..', '')

Payload

../../../../tmp/attacker_authorized_keys

Cite this entry

@misc{vaitp:cve202645309,
  title        = {{AsyncSSH path traversal in %u expansion allows auth with attacker-chosen key.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-45309},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-45309/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::