Packages / basic-ftp / Security

CriticalVulnerabilityGHSA-5rq4-664w-9x2cCVE-2026-27699Published 25 Feb 2026

Basic FTP has Path Traversal Vulnerability in its downloadToDir() method

Your version

Affected releases · basic-ftp

  • 5.x5.0.0 – 5.1.0Fixed in 5.2.0
  • 4.x and older1.0.0 – 4.6.6No fix, no longer updated

On 5.x, the newest line:

npm install basic-ftp@5.2.0
Every release on a timeline
6.x
  1. Not affected

    6.0.0 – 6.2.3

    8 releases, latest

5.x
  1. Affected

    5.0.0 – 5.1.0

    7 releases

  2. Fixed

    5.2.0 – 5.3.1

    5 releases

4.x
  1. Affected

    4.0.0 – 4.6.6

    23 releases

3.x
  1. Affected

    3.0.0 – 3.8.7

    25 releases

2.x
  1. Affected

    2.0.0 – 2.17.1

    45 releases

1.x
  1. Affected

    1.0.0 – 1.2.0

    13 releases

126 stable releases of basic-ftp, oldest to newest, one row per major.

What happens

The basic-ftp library contains a path traversal vulnerability in the downloadToDir() method. A malicious FTP server can send directory listings with filenames containing path traversal sequences (../) that cause files to be written outside the intended download directory.

Source-to-Sink Flow

1. SOURCE: FTP server sends LIST response
└─> "-rw-r--r-- 1 user group 1024 Jan 20 12:00 ../../../etc/passwd"

2. PARSER: parseListUnix.ts:100 extracts filename
└─> file.name = "../../../etc/passwd"

3. VALIDATION: parseListUnix.ts:101 checks
└─> if (name === "." || name === "..") ❌ (only filters exact matches)
└─> "../../../etc/passwd" !== "." && !== ".." ✅ PASSES

4. SINK: Client.ts:707 uses filename directly
└─> const localPath = join(localDirPath, file.name)
└─> join("/safe/download", "../../../etc/passwd")
└─> Result: "/safe/download/../../../etc/passwd" → resolves to "/etc/passwd"

5. FILE WRITE: Client.ts:512 opens file
└─> fsOpen(localPath, "w") → writes to /etc/passwd (outside intended directory)

Vulnerable Code

File: src/Client.ts:707

protected async _downloadFromWorkingDir(localDirPath: string): Promise<void> {
await ensureLocalDirectory(localDirPath)
for (const file of await this.list()) {
const localPath = join(localDirPath, file.name) // ⚠️ VULNERABLE
// file.name comes from untrusted FTP server, no sanitization
await this.downloadTo(localPath, file.name)
}
}

Root Cause: - Parser validation (parseListUnix.ts:101) only filters exact . or .. entries - No sanitization of ../ sequences in filenames

  • path.join() doesn't prevent traversal, fs.open() resolves paths

Impact

A malicious FTP server can: - Write files to arbitrary locations on the client filesystem - Overwrite critical system files (if user has write access) - Potentially achieve remote code execution

Affected Versions

  • Tested: v5.1.0

  • Likely: All versions (code pattern exists since initial implementation)

Mitigation

Workaround: Do not use downloadToDir() with untrusted FTP servers.

Fix: Sanitize filenames before use:

import { basename } from 'path'

// In _downloadFromWorkingDir:
const sanitizedName = basename(file.name) // Strip path components
const localPath = join(localDirPath, sanitizedName)