T09 · Insecure Skill Coding Practices
- Location
scripts/compose-poster.js:273- Finding
Shell Command Injection in ImageMagick Composition
- Content
View full analysis
{ const fontSize = el.size === 'large' ? 48 : el.size === 'medium' ? 32 : 24; const fontWeight = el.weight === 'bold' ? 'bold' : 'normal'; // Calculate position (simplified) let x = 50; // percentage let y = 10 + idx * 15; // percentage if (el.position.includes('center')) x = 50; if (el.position.includes('bottom')) y = 80 + idx * 10; if (el.position.includes('left')) x = 25; if (el.position.includes('right')) x = 75; cmd += ` \\\n -gravity center \\\n -fill white \\\n -stroke black \\\n -strokewidth 2 \\\n -pointsize ${fontSize} \\\n -annotate +0+${(idx - 2) * 60} "${el.text.replace(/"/g, '\\"')}"`; }); cmd += ` "${outputPath}"`; return cmd; } ``` The generated string is subsequently passed to a shell: ```javascript if (hasImageMagick) { // Use ImageMagick const cmd = generateImageMagickCommand(options.image, elements, outputPath); console.error('Running ImageMagick composition...'); execSync(cmd, { stdio: 'inherit' }); result.composed = true; result.method = 'imagemagick'; } ``` ### Technical Analysis The script accepts the input image path, output path, title, subtitle, date, venue, and call-to-action text from command-line arguments. These values are interpolated into one command string that is passed to `child_process.execSync()`. Because `execSync()` executes the string through a system shell, shell metacharacters and substitutions in these arguments are interprete ...[truncated 2477 chars]- Remediation
View remediation
