T09 · Insecure Skill Coding Practices
- Location
scripts/main.ts:113- Finding
OS Command Injection Through the Input Image Path
- Content
View full analysis
{ if (explicitResolution !== "1K") return explicitResolution; try { const { execSync } = await import("node:child_process"); const result = execSync(`identify -format "%w %h" "${inputImagePath}" 2>/dev/null`, { encoding: "utf8" }).trim(); const [w, h] = result.split(" ").map(Number); ``` ### Technical Analysis The user-controlled `inputImagePath` is interpolated directly into a command executed through `execSync`. Because `execSync` receives a string, Node.js invokes a shell to interpret it. Wrapping the path in double quotes does not prevent injection. A filename containing a double quote can terminate the quoted argument and introduce shell operators or additional commands. The earlier `access(args.inputImage)` check does not make the value safe; an attacker can create a file whose name contains shell metacharacters and then supply that exact path. This shell invocation is not necessary for the declared image-generation functionality. Image dimensions should be obtained through a library or by invoking `identify` without a shell. ### Attack Path 1. The attacker creates an accessible image file with a crafted filename containing a quote, shell separator, command, and comment marker. 2. The attacker supplies that path using `--input-image`. 3. The `access()` check succeeds because the crafted file exists. 4. With the default `1K` resolution, `autoDetectResolution()` is called. 5. The crafted path terminates the quoted shell argument. 6. The shell executes the injected command with the same operating-system privileges as the Skill process. ### Impact Assessment Successful exploitation provi ...[truncated 370 chars]- Remediation
View remediation
