Feb 26, 2026·6 min read·158 visits
The `downloadToDir` function in `basic-ftp` (< 5.2.0) blindly trusts filenames sent by the server. A malicious server can return filenames like `../../.ssh/authorized_keys`, causing the client to write outside the sandbox. Fix: Update to 5.2.0.
A critical Path Traversal vulnerability in the popular Node.js `basic-ftp` library allows malicious FTP servers to write arbitrary files to the client's filesystem. By crafting malicious filenames in directory listings, an attacker can escape the intended download directory and overwrite sensitive system files or inject code.
FTP is the cockroach of internet protocols. It survives nuclear wars, modern firewall policies, and the scorn of every security engineer born after 1995. In the Node.js ecosystem, basic-ftp is the go-to library for interacting with these ancient beasts. It's simple, promise-based, and widely used for automated tasks like backing up databases or syncing assets.
But here is the problem with automation: it assumes everyone plays nice. When you connect your client to an FTP server and tell it to "download this directory," you are implicitly trusting that the server will send you... well, files inside that directory. You aren't expecting the server to reach out of the sandbox and stab you in the throat.
CVE-2026-27699 is exactly that stab. It’s a classic Path Traversal vulnerability that turns a standard file download operation into an arbitrary file write primitive. If your application uses basic-ftp to pull data from an untrusted (or compromised) source, your local filesystem is essentially open for business.
The vulnerability hides in plain sight within the _downloadFromWorkingDir method. This function is responsible for recursively downloading a directory from the server to your local machine. The logic seems sound on paper: list the files on the server, iterate through them, and save them locally.
Here is where it goes wrong: the library takes the filename provided by the server and feeds it directly into Node's path.join(). In Node.js, path.join('/safe/dir', '../../evil') resolves to /evil. It dutifully normalizes the path, interpreting the .. segments as instructions to go up the directory tree.
> [!WARNING] > The library failed to ask the most important question in file handling: "Does this file stay where I put it?"
By failing to sanitize the file.name returned by the FTP LIST command, basic-ftp became a 'confused deputy.' It willingly accepts a filename like ../../../../etc/passwd from the server and overwrites the system password file, thinking it's just doing its job.
Let's look at the code before the patch. This is from src/Client.ts. It’s short, readable, and dangerous.
// VULNERABLE CODE (< 5.2.0)
protected async _downloadFromWorkingDir(localDirPath: string): Promise<void> {
await ensureLocalDirectory(localDirPath)
// The server controls 'file.name'
for (const file of await this.list()) {
// FATAL FLAW: No validation on file.name before join
const localPath = join(localDirPath, file.name)
if (file.isDirectory) {
await this.cd(file.name)
// ... recursion ...
} else {
await this.downloadTo(createWriteStream(localPath), file.name)
}
}
}The fix, introduced in version 5.2.0 (Commit 2a2a0e6514357b9eda07c2f8afbd3f04727a7cd9), is elegant in its simplicity. It uses path.basename() to verify that the filename provided by the server doesn't contain any directory separators.
// PATCHED CODE (5.2.0)
+ import { basename, join } from "path"
protected async _downloadFromWorkingDir(localDirPath: string): Promise<void> {
await ensureLocalDirectory(localDirPath)
for (const file of await this.list()) {
// CHECK: Is the basename identical to the name?
// If 'file.name' is '../foo', basename is 'foo'. mismatch -> block.
+ const hasInvalidName = !file.name || basename(file.name) !== file.name
+ if (hasInvalidName) {
+ this.ftp.log(`Invalid filename... skipping`)
+ continue
+ }
const localPath = join(localDirPath, file.name)
// ...
}
}If the server sends ../../evil.exe, basename returns evil.exe. Since ../../evil.exe !== evil.exe, the check fails, and the file is skipped. Simple, but effective.
To exploit this, you don't need fancy buffer overflows. You just need to be the server. This is a "Reverse Client" attack. The victim connects to us.
Scenario: A developer runs a script node backup-fetcher.js that connects to your FTP server to download logs.
pyftpdlib with some modifications to allow raw raw responses).LIST.-rw-r--r-- 1 root root 1024 Feb 25 10:00 ../../../../../home/victim/.ssh/authorized_keysbasic-ftp receives this line. It parses the filename as ../../../../../home/victim/.ssh/authorized_keys. It joins this with the user's download path (e.g., ./downloads)./home/victim/.ssh/authorized_keys. The client opens a write stream to that path. Your server then sends your public SSH key as the file content.Boom. You now have SSH access to the developer's machine.
This vulnerability is rated CVSS 9.1 (Critical) for a reason. While it requires the victim to connect to a malicious server, the consequences are catastrophic.
.bashrc, .ssh/authorized_keys, or placing files in startup folders leads to immediate code execution.web.config, .env) to disable security features or break the application.basic-ftp to pull dependencies or assets from a compromised third-party FTP server, the build artifacts themselves could be backdoored.This isn't just about reading files; it's about writing them anywhere the Node.js process has permission to write. If the script runs as root/admin (God forbid), you own the box.
The remediation is straightforward: Update basic-ftp to version 5.2.0 immediately.
If you cannot update for some reason (maybe you enjoy living dangerously), you must stop using the high-level downloadToDir() method. Instead, you would have to manually implement the directory listing and download logic, ensuring you sanitize every single filename before writing it to disk.
> [!TIP]
> Developer Lesson: Never trust input from the network, even if it looks like a harmless file list. Treat every string from a socket as if it's trying to exploit you. Use path.basename() when handling filenames to ensure they are strictly filenames and not paths.
For security teams: Scan your repositories for package.json files containing "basic-ftp": "<5.2.0". This is a low-effort, high-impact fix.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H| Product | Affected Versions | Fixed Version |
|---|---|---|
basic-ftp Patrick Juchli | < 5.2.0 | 5.2.0 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-22 (Path Traversal) |
| CVSS v3.1 | 9.1 (Critical) |
| Attack Vector | Network (Malicious Server) |
| Affected Component | downloadToDir() / _downloadFromWorkingDir() |
| Exploit Status | PoC Available |
| Patch Date | 2026-02-23 |
The software uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the software does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
NATS Server prior to versions 2.12.8 and 2.14.3 contains an incorrect authorization vulnerability (CWE-863) in its message tracing subsystem. When evaluating whether a connection is permitted to publish trace events to a destination subject specified in the Nats-Trace-Dest header, the server only checks standard client permissions and omits permission checks for leaf node connections. This allows a connected leaf node operator with restricted publishing privileges to emit internal trace events to unauthorized subjects and suppress standard message delivery using the Nats-Trace-Only header.
CVE-2026-63341 is a high-severity Denial of Service (DoS) vulnerability in the Aedes MQTT broker for Node.js affecting all versions prior to 1.1.1. The flaw stems from missing input validation on the hierarchical depth of incoming MQTT topic strings before they are passed to the underlying topic-matching engine, qlobber. Because qlobber enforces a hardcoded limit of 100 topic levels and throws a synchronous exception when this threshold is exceeded, an attacker can send a single MQTT packet containing 101 or more forward-slash-separated levels to trigger an uncaught exception that immediately terminates the Node.js broker process.
CVE-2026-61725 is a path traversal vulnerability (CWE-22) in the sevenz-rust2 Cargo package prior to version 0.21.1. The vulnerability occurs because the decompression utility fails to validate or sanitize archive entry filenames before joining them with the destination directory path via std::path::Path::join. An attacker who supplies a crafted 7z archive containing parent directory traversal sequences or absolute paths can write or overwrite arbitrary files on the host filesystem with the privileges of the extracting process.
CVE-2026-77309 (GHSA-jrjx-9jjw-747m) is a high-severity unauthenticated remote code execution vulnerability affecting NASA-AMMOS AIT-GUI versions 1.0.0 through 2.5.0. The flaw results from chaining an incomplete file cleanup error in the telemetry query endpoint (/tlm/query) with a directory traversal flaw in the script execution endpoint (/script/run). An attacker on an adjacent network can stage arbitrary Python statements into a static file on disk and execute that file under the privileges of the AIT-GUI web server process.
A vulnerability classified under CWE-116 (Improper Encoding or Escaping of Output) exists in memtomem-stm versions 0.1.0 through 0.1.33. The software acts as a Model Context Protocol (MCP) short-term memory proxy gateway for AI agent architectures. When surfacing retrieved memories and scratchpad items into downstream Large Language Model (LLM) context envelopes, the SurfacingFormatter component fails to properly sanitize untrusted memory attributes. An attacker with the ability to plant untrusted content into the agent's long-term or working memory store can inject arbitrary structural delimiters, close the <surfaced-memories> XML boundary prematurely, visually obscure instructions using Unicode bidirectional overrides, and execute stored prompt injection attacks against downstream LLM agents.
CVE-2026-77331 (GHSA-72jh-722p-rqr3) is a concurrency and session-state synchronization vulnerability in memtomem-stm, a short-term memory proxy gateway for AI agents. In versions 0.1.2 prior to 0.1.34, concurrent Model Context Protocol (MCP) Remote Procedure Call (RPC) failures or mid-flight task cancellations can initiate duplicate reconnect loops and permit dirty or cancelled transport sessions to be reused. This deficiency results in session-state integrity loss and local service degradation.