T09 · Insecure Skill Coding Practices
- Location
scripts/image-generator.ts:62- Finding
Shell Command Injection Through Prompts and Output Paths
- Content
View full analysis
{ const cmd = `opencli gemini image "${escapeShell(prompt)}" --rt ${ar} --op "${escapeShell(outDir)}" -f json --timeout 300`; const { stdout } = await execAsync(cmd, { timeout: 310_000 }); let parsed: any; try { parsed = JSON.parse(stdout); } catch { // Try to find JSON in output (opencli may emit logs before JSON) const jsonMatch = stdout.match(/\[[\s\S]*\]|\{[\s\S]*\}/); if (!jsonMatch) throw new Error(`Gemini: could not parse JSON output: ${stdout.slice(0, 500)}`); parsed = JSON.parse(jsonMatch[0]); } // opencli gemini image output columns: status, file, link const items = Array.isArray(parsed) ? parsed : parsed.results || parsed.images || [parsed]; const success = items.find((item: any) => item.status === "success" || item.file); if (!success?.file) { throw new Error(`Gemini: no successful image in output. Status: ${JSON.stringify(items.slice(0, 2))}`); } const imagePath = success.file as string; console.log(` ✓ Gemini image saved: ${imagePath}`); return { imagePath }; } async function runGrokImage( prompt: string, outDir: string ): Promise<{ imagePath: string }> { const cmd = `opencli grok image "${escapeShell(prompt)}" --out "${escapeShell(outDir)}" -f json --timeout 300 --count 1`; const { stdout } = await execAsync(cmd, { timeout: 310_000 }); let parsed: any; try { parsed = JSON.parse(stdout); } catch { const jsonMatch = stdout.match(/\[[\s\S]*\]|\{[\s\S]*\}/); if (!jsonMatch) throw new Error(`Grok: could not parse JSON output: ${stdout.slice(0, 500)}`); parsed = JSON.parse(jsonMatch[0]); } // opencli grok im ...[truncated 3683 chars]- Remediation
View remediation
