Summary
AsyncSSH's SFTP path mapping can allow an authenticated SFTP user to escape the configured chroot by supplying a path with a particular leading-slash form. This may enable the user to read or write files accessible to the server's operating-system account, and code execution may be possible if suitable targets are writable.
Affected context
The issue occurs in AsyncSSH's SFTPServer.map_path() when client-supplied paths are normalized and then joined with the configured chroot. It affects configurations where the path handling leaves a double-leading-slash form that is treated as absolute during the join. Exploitation requires an authenticated SFTP user and is limited by the operating-system permissions of the account running the server.
Exploit preconditions
- Attack surface: AsyncSSH SFTP server path handling
- Required access: An authenticated account with SFTP access
- Trigger point: Mapping a client-supplied path to the configured chroot
- Why exploitation is possible: Normalization can preserve a double-leading-slash form, and removing only one leading slash can leave a path that the subsequent join treats as absolute, bypassing the chroot
Why this happens
The path mapping logic does not ensure that the normalized client path remains relative to the configured chroot. POSIX path normalization may preserve a double-leading-slash prefix, and joining that result with the chroot can cause the path to be interpreted as absolute. This is a path traversal issue, mapped primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory; it also relates to CWE-50: Pathname Equivalence, because differing path representations can bypass intended restrictions.
Potential impact
- An authenticated user may read files accessible to the server account outside the chroot.
- An authenticated user may modify or create files where the server account has write permission.
- Code execution could occur if the user can modify a file that is later executed or loaded by another process.
- The confidentiality and integrity of data available to the server account may be affected.
General mitigation guidance
Defensive patterns focus on enforcing directory containment after path resolution, rather than relying on slash removal or normalization alone.
- Resolve candidate paths against the configured root and verify they remain within it before performing file operations.
- Reject or consistently canonicalize ambiguous path forms, including paths with repeated leading separators.
- Use filesystem APIs and access controls that constrain SFTP operations to a dedicated directory.
- Run the SFTP service with a minimally privileged operating-system account and limit writable locations.
- Treat client-supplied paths as untrusted regardless of authentication.
How teams detect issues like this
- Use static analysis to identify path joins involving client-controlled values without a subsequent containment check.
- Review path normalization and chroot mapping code for inconsistent handling of leading separators and absolute paths.
- Add tests and policy checks that cover equivalent path representations and confirm resolved paths remain inside the configured root.
- Monitor SFTP activity for access attempts outside expected directory boundaries and unexpected changes to sensitive files.

