/

CVE-2026-27699

Severity:

CRITICAL RISK

(9.1)

Path Traversal in basic-ftp Node.js Client downloadToDir()

CVE-2026-27699

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write Outside Intended Directory

Severity:

CRITICAL RISK

(9.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

The basic-ftp Node.js client library contains a path traversal flaw in the downloadToDir() method that allows a malicious FTP server to influence where files are written on the client's filesystem.

By returning directory listings with ../ segments in filenames, a compromised or hostile FTP server can cause files to be stored outside the intended download directory, potentially overwriting or planting files in sensitive paths.

Affected context

This vulnerability affects applications using basic-ftp versions prior to 5.2.0 that call downloadToDir() to recursively download files from an FTP server.

The issue appears when client code assumes the remote server is trustworthy, and relies on downloadToDir() to enforce a local download boundary.

Any scenario where the FTP server is not fully trusted, can be controlled by an attacker, or can be man-in-the-middled increases the practical risk of this bug.

Exploit preconditions

  • Attack surface: Client systems running Node.js applications that use basic-ftp to download from FTP servers.
  • Required access: Ability to control or impersonate the FTP server, or to tamper with FTP directory listings in transit.
  • Trigger point: A call to downloadToDir() that processes directory listings containing filenames or paths with traversal patterns such as ../.
  • Why exploitation is possible: The client library fails to canonicalize and validate server-supplied paths against the intended download root, allowing traversal segments to influence the final local file path.

Why this happens

The core issue is a missing normalization and validation step when translating server-provided paths into local filesystem paths.

The downloadToDir() method trusts filenames and directory entries supplied by the FTP server, concatenating them with a local base directory without removing or rejecting .. components or absolute path constructs.

This aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where user- or externally-controlled path input is not constrained to remain within an expected directory boundary.

Potential impact

  • Attacker-controlled files could be written outside the designated download directory.
  • Existing files in writable paths (e.g., application data, configuration files, logs) could be overwritten.
  • Malicious scripts or executables could be planted in locations that may later be executed by users, system services, or deployment tooling.
  • Sensitive data integrity could be compromised by tampered assets, leading to downstream security or reliability issues.

General mitigation guidance

Effective mitigation centers on strict path normalization and enforcement of directory boundaries on the client side.

General defensive patterns include:

  • Canonicalizing server-supplied paths (e.g., using path.resolve) and verifying that the result remains under the intended download root before any file operations.
  • Rejecting or sanitizing path components containing .., absolute paths, or unusual separators when mapping remote paths to local ones.
  • Applying least-privilege file-system permissions so the process downloading files can write only to dedicated, non-sensitive directories.
  • Isolating downloaded content (e.g., in a sandboxed or temporary directory) and validating files before promoting them into more privileged locations or using them in production flows.
  • Treating all data from FTP servers as untrusted, especially when servers are external, shared, or unauthenticated.

How teams detect issues like this

Organizations can investigate and monitor for this class of issue using:

  • Static analysis and code scanning: Look for uses of downloadToDir() or similar file download routines where remote paths are concatenated with local directories without normalization and boundary checks.
  • Code review practices: Flag any file-write logic that directly uses server-supplied or user-supplied path components, and verify that canonical path comparisons against an allowed root are in place.
  • Runtime monitoring: Enable file integrity monitoring or logging on client systems to detect unexpected writes outside designated download directories when downloads occur.
  • Policy enforcement: Incorporate security checks into CI pipelines to require path traversal defenses in file handling utilities and to discourage trusting path information from remote services by default.

Sources

SourceLink
github.comgithub.com/patrickjuchli/basic-ftp/commit/2a2a0e6514357b9eda07c2f8afbd3f04727a7cd9
github.comgithub.com/patrickjuchli/basic-ftp/releases/tag/v5.2.0
github.comgithub.com/patrickjuchli/basic-ftp/security/advisories/GHSA-5rq4-664w-9x2c

Frequently asked

questions

Yes. A remote attacker who controls or can impersonate the FTP server can exploit this vulnerability when a client application initiates a downloadToDir() operation.

The attacker needs control over the FTP server or the ability to modify directory listings in transit. No additional access to the client host is required beyond the client connecting to the malicious or compromised server.

The safest approach is to normalize all server-supplied paths, then enforce that the resolved path remains within the designated download directory before performing any file operations. Any paths that traverse outside the allowed directory should be rejected or sanitized.

Treat all externally supplied paths as untrusted, consistently apply canonicalization and directory-boundary checks, minimize filesystem write permissions for network-facing processes, and include path traversal checks as a standard part of security review for file handling code.

Find out what's already
exploitable in your codebase.