T09 · Insecure Skill Coding Practices
- Location
scripts/server.cjs:163- Finding
Unauthenticated HTTP and WebSocket Service Can Expose Session Content
- Content
View full analysis
isFullDocument(raw) ? raw : wrapInFrame(raw))(fs.readFileSync(screenFile, 'utf-8')) : WAITING_PAGE; if (html.includes('')) { html = html.replace('', helperInjection + '\n'); } else { html += helperInjection; } res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.end(html); } else if (req.method === 'GET' && req.url.startsWith('/files/')) { const fileName = req.url.slice(7); const filePath = path.join(CONTENT_DIR, path.basename(fileName)); if (!fs.existsSync(filePath)) { res.writeHead(404); res.end('Not found'); return; } const ext = path.extname(filePath).toLowerCase(); const contentType = MIME_TYPES[ext] || 'application/octet-stream'; res.writeHead(200, { 'Content-Type': contentType }); res.end(fs.readFileSync(filePath)); } else { res.writeHead(404); res.end('Not found'); } } const clients = new Set(); function handleUpgrade(req, socket) { const key = req.headers['sec-websocket-key']; if (!key) { socket.destroy(); return; } const accept = computeAcceptKey(key); socket.write( 'HTTP/1.1 101 Switching Protocols\r\n' + 'Upgrade: websocket\r\n' + 'Connection: Upgrade\r\n' + 'Sec-WebSocket-Accept: ' + accept + '\r\n\r\n' ); let buffer = Buffer.alloc(0); clients.add(socket); ``` ```javascript server.listen(PORT, HOST, () => { const info = JSON.stringify({ type: 'server-started', port: Number(PORT), host: H ...[truncated 2230 chars]- Remediation
View remediation
