T05 · Unauthorized Access and Privilege Escalation
- Location
server.js:20- Finding
Unauthenticated filesystem disclosure and arbitrary file overwrite
- Content
View full analysis
{ body += chunk.toString(); }); req.on('end', () => { try { const { path: filePath, content } = JSON.parse(body); const fullPath = path.join(ENGINE_DIR, filePath); // Security: only allow writes within engine directory if (!fullPath.startsWith(ENGINE_DIR)) { res.writeHead(403, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Path outside engine directory' })); return; } fs.writeFileSync(fullPath, content, 'utf8'); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ success: true })); } catch (error) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: error.message })); } }); return; } // READ endpoint (GET files) let filePath = parsedUrl.pathname === '/' ? '/index.html' : parsedUrl.pathname; filePath = path.join(ENGINE_DIR, filePath); const ext = path.extname(filePath); const contentType = mimeTypes[ext] || 'application/octet-stream'; fs.read ...[truncated 2628 chars]- Remediation
View remediation
