T05 · Unauthorized Access and Privilege Escalation
- Location
src/index.ts:101- Finding
Symbolic Links Can Disclose Arbitrary Local Files Through Prepared and Published Bundles
- Content
View full analysis
{ const entries = await fse.readdir(dir, { withFileTypes: true }); const files: string[] = []; for (const entry of entries) { const abs = path.join(dir, entry.name); const rel = path.relative(root, abs); if (entry.isDirectory()) { if (EXCLUDED_DIRS.has(entry.name)) continue; files.push(...await walk(abs, root)); } else { if (EXCLUDED_FILES.has(entry.name)) continue; files.push(rel); } } return files.sort(); } ``` ```ts function isTextFile(rel: string) { const ext = getExtension(rel); return TEXT_EXTENSIONS.has(ext) || !BINARY_EXTENSIONS.has(ext); } ``` ```ts for (const rel of sourceFiles) { const source = path.join(absDir, rel); const dest = path.join(outputDir, rel); const raw = isTextFile(rel) ? await readText(source).catch(() => '') : ''; const likelyBlank = isTextFile(rel) && !raw.trim(); const shouldSkip = likelyBlank && rel !== 'SKILL.md'; if (shouldSkip) { removedFiles.push(rel); continue; } await fse.ensureDir(path.dirname(dest)); if (isTextFile(rel)) { await fse.writeFile(dest, normalizeLines(raw), 'utf8'); } else { await fse.copy(source, dest); } copiedFiles.push(rel); } ``` ### Technical Analysis The directory walker does not distinguish symbolic links from ordinary files. A symbolic link is not reported as a directory by `Dirent.isDirectory()`, so it enters the file list. During preparation, `readText()` ultimately calls `readFile()`, which follows the link and reads its target. The permissive `isTextFile()` implementation also classifies every extension not explicitly listed as binary as text. Consequently, an attacker can give a symlink ...[truncated 1371 chars]- Remediation
View remediation
'')`. 6. Repeat containment validation immediately before reading to reduce time-of-check/time-of-use exposure. 7. Add automated tests covering file symlinks, directory symlinks, nested links, broken links, and links to files outside the source root. ]]>
