T09 · Insecure Skill Coding Practices
- Location
index.js:126- Finding
Filesystem Reorganization Executes Without Explicit User Confirmation
- Content
View full analysis
Vulnerability Details
File Location:
index.js, lines 126-206
Vulnerability Type: Unconfirmed destructive filesystem operation
Risk Level: MediumVulnerable Code
js // Activation condition activate(message) { const keywords = ['整理', '分类']; return keywords.some(k => message.includes(k)); }, async handle(context) { const message = context.message || ''; const lowerMessage = message.toLowerCase(); // Resolve the target path let targetPath = null; if (lowerMessage.includes('桌面')) { targetPath = path.join(process.env.USERPROFILE || '', 'Desktop'); } else if (lowerMessage.includes('下载')) { targetPath = path.join(process.env.USERPROFILE || '', 'Downloads'); } else if (lowerMessage.includes('文档')) { targetPath = path.join(process.env.USERPROFILE || '', 'Documents'); } // Query requests only display statistics if (lowerMessage.includes('统计') || lowerMessage.includes('查看')) { const stats = generateReport(scanResults); // Report generation omitted return { message: msg }; } // All other matching requests immediately reorganize the files const organizeResults = organizeFiles(scanResults.files, targetPath); }The resulting filesystem operation is implemented at
index.js, lines 67-103:js function organizeFiles(files, targetDir) { const results = { moved: [], errors: [] }; const categories = [...new Set(files.map(f => f.type))]; for (const category of categories) { const categoryDir = path.join(targetDir, category); if (!fs.existsSync(categoryDir)) { fs.mkdirSync(categoryDir, { recursive: true }); } } for (const file of files) { try { const targetPath = path.join(targetDir, file.type, file.name); let finalPath = targetPath; let counter = 1; while (fs.existsSync(finalPath)) { const nameWithoutExt = path.basename(file.name, file.ext); finalPath = path.join( targetDir, file ...[truncated 3542 chars]- Remediation
View remediation
Remediation Suggestions
-
Default to preview-only behavior. Display the resolved absolute path, affected file count, category mapping, and proposed source-to-destination operations without modifying the filesystem.
-
Require explicit confirmation. Execute only after a separate confirmation message that includes or cryptographically binds the exact target path and preview identifier. Generic organization-related wording must not authorize filesystem changes.
-
Use an explicit execution mode. Separate commands such as
preview,confirm, andcancel. Do not infer permission to mutate files merely from the absence of statistics-related keywords. -
Create a rollback manifest. Before moving files, persist an atomic manifest containing every original and destination path. Provide a restore operation that validates the manifest and reverses completed moves.
-
Restrict allowed roots. Require target directories to be inside administrator- or user-configured safe roots. Resolve paths with
path.resolve, verify containment, and reject unexpected system or application directories. -
Handle missing environment variables safely. Do not construct relative fallback paths such as
DesktopwhenUSERPROFILEis absent. Return an error and request an explicit absolute path instead. -
Reduce activation ambiguity. Require a specific command or structured invocation rather than broad substring matching.
-
Make execution failure-safe. Validate all proposed destinations before the first move. If any move fails, either roll back completed operations or clearly report the exact partial state.
-
Add tests for authorization boundaries. Verify that ambiguous messages, indirect content, preview requests, absent environment variables, and malformed paths cannot trigger filesystem mutation.
-
