T09 · Insecure Skill Coding Practices
- Location
scripts/biolims-openai-server.mjs:22- Finding
Unauthenticated Remote Shell Command Injection in the OpenAI-Compatible Server
- Content
View full analysis
`"${a}"`).join(' ')}`; const result = execSync(cmd, { encoding: 'utf-8', timeout: 30000 }); return JSON.parse(result); } catch (err) { return { status: 500, msg: err.message }; } } ``` ```javascript // Direct command mode: /command arg1 arg2 if (message.startsWith('/')) { const parts = message.slice(1).split(/\s+/); return { command: parts[0], args: parts.slice(1) }; } ``` ```javascript // Validate API Key (optional) const authHeader = req.headers.authorization; if (API_KEY && authHeader !== `Bearer ${API_KEY}`) { res.writeHead(401, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: { message: 'Invalid API key', type: 'invalid_request_error' } })); return; } ``` ```javascript server.listen(PORT, () => { ``` ### Technical Analysis The server accepts a user-controlled chat message and supports a direct-command syntax beginning with `/`. The resulting command name and arguments are interpolated into a single command string passed to `execSync()`. Because `execSync()` executes a string through a shell, shell metacharacters embedded in the command or arguments can alter the intended command and execute additional operating-system commands. Wrapping arguments in double quotes is not sufficient because shell substitutions and quote-breaking input may still be interpreted. The service has two conditions that significantly increase exploitability: 1. `BIOLIMS_API_KEY` defaults to an empty s ...[truncated 1948 chars]- Remediation
View remediation
