T09 · Insecure Skill Coding Practices
- Location
scripts/batch-generate.js:60- Finding
Unsafe deletion of pre-existing media files in the output directory
- Content
View full analysis
1) { for (let i = 1; i < files.length; i++) { try { fs.unlinkSync(files[i].path); console.log(` 🗑️ 清理多余文件: ${files[i].name}`); } catch (e) { /* 忽略 */ } } } } ``` The files subject to this operation are selected by the following code at lines 49-59: ```javascript function getVideoFiles() { return fs.readdirSync(OUTPUT_DIR) .filter(f => f.startsWith('video-') && (f.endsWith('.mp4') || f.endsWith('.jpg'))) .map(f => ({ name: f, path: path.join(OUTPUT_DIR, f), mtime: fs.statSync(path.join(OUTPUT_DIR, f)).mtime })) .sort((a, b) => b.mtime - a.mtime); } ``` ### Technical Analysis The cleanup routine deletes every matching `video-*.mp4` or `video-*.jpg` file except the most recently modified one. It does not verify that the files were generated by the current process, belong to the current project, or are recorded in a trusted temporary-file manifest. The output directory is supplied by the user through `--output`. If the user selects an existing directory containing unrelated media with matching names, the script treats those files as disposable generation artifacts. Errors are silently ignored, reducing visibility into destructive behavior. This exceeds the minimum file-system privileges required for batch generation. The Skill only needs to create and rename artifacts generated during the current run; it does not need to delete arbitrary pre-existing matching files. ### Attack Path 1. A user supplies an existing directory through `--output`. 2. That directory contains two or more valuable files named in the `video-*.mp4` or `video-*.jpg` pattern. 3. `cleanupExtraVideoFiles()` enumerates all matching files ...[truncated 925 chars]- Remediation
View remediation
