You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
basic-ftp@5.2.2 is vulnerable to denial of service through unbounded memory growth while processing directory listings from a remote FTP server. A malicious or compromised server can send an extremely large or never-ending listing response to Client.list(), causing the client process to consume memory until it becomes unstable or crashes.
Details
The issue is in the package's default directory listing flow.
Client.list() reaches dist/Client.js, where the full listing response is downloaded into a StringWriter before parsing:
The vulnerable sink is StringWriter, which grows an in-memory Buffer with no limit:
File: dist/StringWriter.js:5-20
classStringWriterextendsstream_1.Writable{constructor(){super(...arguments);this.buf=Buffer.alloc(0);}_write(chunk,_,callback){if(chunkinstanceofBuffer){this.buf=Buffer.concat([this.buf,chunk]);callback(null);}else{callback(newError("StringWriter expects chunks of type 'Buffer'."));}}getText(encoding){returnthis.buf.toString(encoding);}}
The critical operation is:
this.buf=Buffer.concat([this.buf,chunk]);
There is no maximum size check, no truncation, and no streaming parser. Because the remote FTP server controls the listing response, it can force the client to keep allocating memory until the process is terminated.
How it happens:
An application connects to an attacker-controlled or compromised FTP server.
The application calls client.list().
The server returns an extremely large or unbounded directory listing.
basic-ftp buffers the full response in StringWriter.
Memory grows without bound due to repeated Buffer.concat(...) calls.
PoC
The following PoC exercises the vulnerable buffering primitive directly:
const{ StringWriter }=require("basic-ftp/dist/StringWriter.js");functionmb(n){returnMath.round(n/1024/1024)+"MB";}constwriter=newStringWriter();letwrote=0;for(leti=0;i<32;i++){constchunk=Buffer.alloc(4*1024*1024,0x41);writer.write(chunk);wrote+=chunk.length;if((i+1)%8===0){constm=process.memoryUsage();console.log("written",mb(wrote),"rss",mb(m.rss),"heap",mb(m.heapUsed),"buf",mb(m.arrayBuffers));}}console.log("final text len",writer.getText("utf8").length);
Observed output:
written 32MB rss 116MB heap 4MB buf 64MB
written 64MB rss 296MB heap 4MB buf 240MB
written 96MB rss 340MB heap 3MB buf 284MB
written 128MB rss 436MB heap 3MB buf 376MB
final text len 134217728
This demonstrates sustained memory growth in the same code path used to buffer directory listing data.
Supporting files saved alongside this report:
poc.js
poc_output.txt
Impact
This is a denial-of-service vulnerability affecting applications that use basic-ftp to list directories from remote FTP servers.
Vulnerability class: Memory exhaustion / Denial of Service
Attack precondition: The victim connects to a malicious or compromised FTP server and performs Client.list()
Impacted users: Any application or service using basic-ftp@5.2.2 against untrusted FTP endpoints
Security effect: The attacker can cause excessive memory consumption, process instability, and potential process termination
Recommended remediation:
Enforce a maximum listing size.
Abort transfers that exceed the configured limit.
Prefer incremental or streaming parsing over full-response buffering.
Example defensive check:
if(this.buf.length+chunk.length>MAX_LISTING_BYTES){callback(newError("FTP listing exceeds maximum allowed size."));return;}this.buf=Buffer.concat([this.buf,chunk]);
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
=5.2.2→=5.3.0GitHub Vulnerability Alerts
GHSA-rp42-5vxx-qpwr
Summary
basic-ftp@5.2.2is vulnerable to denial of service through unbounded memory growth while processing directory listings from a remote FTP server. A malicious or compromised server can send an extremely large or never-ending listing response toClient.list(), causing the client process to consume memory until it becomes unstable or crashes.Details
The issue is in the package's default directory listing flow.
Client.list()reachesdist/Client.js, where the full listing response is downloaded into aStringWriterbefore parsing:File:
dist/Client.js:516-527The vulnerable sink is
StringWriter, which grows an in-memoryBufferwith no limit:File:
dist/StringWriter.js:5-20The critical operation is:
There is no maximum size check, no truncation, and no streaming parser. Because the remote FTP server controls the listing response, it can force the client to keep allocating memory until the process is terminated.
How it happens:
client.list().basic-ftpbuffers the full response inStringWriter.Buffer.concat(...)calls.PoC
The following PoC exercises the vulnerable buffering primitive directly:
Observed output:
This demonstrates sustained memory growth in the same code path used to buffer directory listing data.
Supporting files saved alongside this report:
poc.jspoc_output.txtImpact
This is a denial-of-service vulnerability affecting applications that use
basic-ftpto list directories from remote FTP servers.Client.list()basic-ftp@5.2.2against untrusted FTP endpointsRecommended remediation:
Example defensive check:
Severity
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:HRelease Notes
patrickjuchli/basic-ftp (get-uri>basic-ftp)
v5.3.0Compare Source
Configuration
📅 Schedule: (in timezone America/Los_Angeles)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.