Summary
A path traversal flaw in the AsyncSSH SCP client allows a malicious SSH server to write files outside the intended download directory by abusing server-controlled filenames.
When the client connects to an untrusted or compromised SCP server, crafted ../ sequences in filenames can cause arbitrary files to be created or overwritten on the client's filesystem.
Affected context
This vulnerability affects environments where AsyncSSH is used as an SCP client to pull files from remote SSH servers over asyncio.
The risk materializes when the client interacts with servers that are untrusted, misconfigured, or potentially compromised and is configured to accept server-provided filenames without additional validation.
The issue arises specifically in the code paths where server-controlled filenames are joined with a client-specified destination directory, but no checks enforce that the resulting paths remain within that directory.
Exploit preconditions
- Attack surface: AsyncSSH-based SCP client operations receiving files from remote SSH servers.
- Required access: Ability to operate or compromise the SSH/SCP server the client connects to, or to intercept and manipulate SCP protocol file metadata.
- Trigger point: The SCP client receives filenames containing
../sequences or absolute-like path components which are then joined to the destination directory. - Why exploitation is possible: The
_parse_cd_argsfunction returns server-provided names verbatim, and_recv_filesblindly joins them with the target path without normalizing or enforcing that the computed path stays within the intended directory boundary.
Why this happens
The underlying bug class is path traversal due to improper validation of externally supplied path components, mapped to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
In AsyncSSH's SCP client, server-provided filenames and directory arguments are treated as trusted and concatenated with the user's selected destination directory using standard path-joining APIs.
Because no canonicalization, normalization, or boundary checks are applied, attackers can embed ../ sequences or other constructs that escape the destination directory, leading the client to write files into arbitrary locations on the local filesystem.
Potential impact
- Remote server can write files to arbitrary locations on the SCP client's filesystem.
- Important configuration or application files may be overwritten, potentially leading to service disruption.
- Malicious scripts or binaries could be planted in locations that are later executed by the user or automated processes.
- Local privilege escalation may be possible if written files influence privileged services or trust relationships.
- Data integrity and confidentiality may be compromised through unauthorized file creation or modification.
General mitigation guidance
Mitigation generally focuses on constraining how path information from untrusted sources is handled and enforcing strict directory boundaries for file operations.
Common defensive patterns include:
- Normalizing and canonicalizing all server-provided filenames before use, then verifying that their resolved paths remain under the intended destination directory.
- Rejecting or sanitizing any filename containing
.., absolute path indicators, or unexpected path separators when accepting files from remote peers. - Using secure-by-default file transfer abstractions that explicitly restrict operations to a predefined sandbox or chroot-like directory.
- Running SCP client processes with least privilege, ensuring that even if directory traversal occurs, the process cannot write into sensitive system locations.
- Treating all server-controlled metadata, including filenames and directory names, as untrusted input subject to validation rather than direct concatenation.
How teams detect issues like this
Organizations can detect and manage similar path traversal issues through:
- Static analysis rules that flag direct concatenation of untrusted path components (e.g., network or protocol fields) with local filesystem paths without normalization or boundary checks.
- Code review practices that require explicit checks to ensure joined paths stay under expected root directories, using functions like realpath-based comparisons or path traversal guards.
- Secure coding guidelines and linting policies that discourage accepting filenames from remote peers verbatim and mandate input validation for path-related data.
- Optional use of dynamic analysis or runtime monitoring tools that can log and alert on unexpected write operations outside designated directories by client applications.

