{"id":"GHSA-5rq4-664w-9x2c","revision":"6db4f81cc79146c0a6a54ed30e80423e","records":[{"revision":"6db4f81cc79146c0a6a54ed30e80423e","observedAt":"2026-10-24T13:17:17.793+00:00","statement":{"source":"osv","id":"GHSA-5rq4-664w-9x2c","aliases":["CVE-2026-27699"],"title":"Basic FTP has Path Traversal Vulnerability in its downloadToDir()\u00A0method","description":"The `basic-ftp`\u00A0library contains a path traversal vulnerability in the `downloadToDir()`\u00A0method. 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.\n\n\n## Source-to-Sink Flow\n\n```\n1. SOURCE: FTP server sends LIST response\n└─> \"-rw-r--r-- 1 user group 1024 Jan 20 12:00 ../../../etc/passwd\"\n\n2. PARSER: parseListUnix.ts:100 extracts filename\n└─> file.name = \"../../../etc/passwd\"\n\n3. VALIDATION: parseListUnix.ts:101 checks\n└─> if (name === \".\" || name === \"..\") ❌ (only filters exact matches)\n└─> \"../../../etc/passwd\" !== \".\" && !== \"..\" ✅ PASSES\n\n4. SINK: Client.ts:707 uses filename directly\n└─> const localPath = join(localDirPath, file.name)\n└─> join(\"/safe/download\", \"../../../etc/passwd\")\n└─> Result: \"/safe/download/../../../etc/passwd\" → resolves to \"/etc/passwd\"\n\n5. FILE WRITE: Client.ts:512 opens file\n└─> fsOpen(localPath, \"w\") → writes to /etc/passwd (outside intended directory)\n```\n\n## Vulnerable Code\n\n**File**: `src/Client.ts:707`\n\n```typescript\nprotected async _downloadFromWorkingDir(localDirPath: string): Promise<void>\u00A0{\nawait ensureLocalDirectory(localDirPath)\nfor\u00A0(const file of await\u00A0this.list()) {\nconst localPath = join(localDirPath, file.name) // ⚠️ VULNERABLE\n// file.name comes from untrusted FTP server, no sanitization\nawait this.downloadTo(localPath, file.name)\n}\n}\n```\n\n**Root Cause**:\n-\u00A0Parser validation (`parseListUnix.ts:101`) only filters exact `.`\u00A0or `..`\u00A0entries\n-\u00A0No sanitization of `../`\u00A0sequences in filenames\n- `path.join()`\u00A0doesn't prevent traversal, `fs.open()`\u00A0resolves paths\n\n\n# Impact\n\nA malicious FTP server can:\n-\u00A0Write files to arbitrary locations on the client filesystem\n-\u00A0Overwrite critical system files (if user has write access)\n-\u00A0Potentially achieve remote code execution\n\n## Affected Versions\n\n- **Tested**: v5.1.0\n- **Likely**: All versions (code pattern exists since initial implementation)\n\n## Mitigation\n\n**Workaround**: Do not use `downloadToDir()`\u00A0with untrusted FTP servers.\n\n**Fix**: Sanitize filenames before use:\n\n```typescript\nimport\u00A0{ basename\u00A0} from 'path'\n\n// In _downloadFromWorkingDir:\nconst sanitizedName = basename(file.name) // Strip path components\nconst localPath = join(localDirPath, sanitizedName)\n```","state":0,"publishedAt":"2026-02-25T22:34:26+00:00","modifiedAt":"2026-09-10T03:50:34.1557008+00:00","affected":[{"ecosystem":"npm","name":"basic-ftp","ranges":[{"type":"SEMVER","events":[{"kind":"introduced","version":"0"},{"kind":"fixed","version":"5.2.0"}]}],"versions":[],"rawVersionEvidence":null}],"metrics":[{"system":"CVSS_V3","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H","score":null,"severity":null},{"system":"Publisher rating","vector":null,"score":null,"severity":"CRITICAL"}],"references":["https://github.com/patrickjuchli/basic-ftp/security/advisories/GHSA-5rq4-664w-9x2c","https://nvd.nist.gov/vuln/detail/CVE-2026-27699","https://github.com/patrickjuchli/basic-ftp/commit/2a2a0e6514357b9eda07c2f8afbd3f04727a7cd9","https://github.com/patrickjuchli/basic-ftp","https://github.com/patrickjuchli/basic-ftp/releases/tag/v5.2.0"],"sourceUrl":"https://github.com/advisories/GHSA-5rq4-664w-9x2c","license":"GitHub Advisory Database · CC-BY-4.0","key":"osv:GHSA-5rq4-664w-9x2c","identifiers":["GHSA-5rq4-664w-9x2c","CVE-2026-27699"]},"retained":false,"historicalAffected":[]}],"coverage":[]}