T09 · Insecure Skill Coding Practices
- Location
server/index.js:325- Finding
Unauthenticated Shell Command Injection in Folder-Opening Endpoint
- Content
View full analysis
{ try { const { path: folderPath } = req.body; if (!folderPath) { return res.status(400).json({ success: false, error: 'Path cannot be empty' }); } if (!fs.existsSync(folderPath)) { return res.status(404).json({ success: false, error: 'Folder does not exist' }); } const { exec } = require('child_process'); let command; if (process.platform === 'win32') { command = `explorer "${folderPath}"`; } else if (process.platform === 'darwin') { command = `open "${folderPath}"`; } else { command = `xdg-open "${folderPath}"`; } res.json({ success: true, msg: 'Folder opened' }); exec(command, (error) => { if (error) { console.error('Failed to open folder:', error); } }); } catch (error) { console.error('Open-folder exception:', error); res.status(500).json({ success: false, error: error.message }); } }); ``` ### Technical Analysis The endpoint directly interpolates the attacker-controlled `folderPath` into a command executed through `child_process.exec()`. `exec()` invokes a command shell, so shell metacharacters contained in the path can terminate or alter the intended command. Surrounding the value with double quotes does not reliably prevent shell injection. The `fs.existsSync()` check is not a security boundary. An attacker can construct input containing an existing path followed by platform-specific shell syntax. The endpoint has no authentication or authorization. Opening a generated-work folder is a legitimate feature, but accepting arbitrary paths and invoking a shell exceeds the minimum privilege needed for that feature. ### Attack Path 1. The attacker reaches TCP port 2688. 2. The attacker sub ...[truncated 655 chars]- Remediation
View remediation
