T09 · Insecure Skill Coding Practices
- Location
references/examples-advanced.md:353- Finding
Shell Command Injection in Reusable Production Templates
- Content
View full analysis
Vulnerability Details
File Location:
references/examples-advanced.md:88-90, 128-130, 353-355, 566-568, 581-583, 742-744;references/extension-points.md:132-135, 509-513
Vulnerability Type: OS command injection through unsafe shell-string construction
Risk Level: HighThe affected documentation presents these examples as complete, production-ready patterns. The packaged
index.jsdoes not invoke them directly, but applications that copy or extend these templates can expose command execution to untrusted options, configuration values, filenames, API parameters, report definitions, and log content.Vulnerable Code
references/examples-advanced.md:88-90:javascript const result = await exec({ command: `cat ${options.input}` });references/examples-advanced.md:128-130:javascript const result = await exec({ command: `iconv -f UTF-8 -t ASCII//TRANSLIT ${options.input}` });references/examples-advanced.md:353-355:javascript const result = await exec({ command: `curl -s -X ${method} ${endpoint} ${this.formatHeaders(headers)} ${this.formatData(data)}` });references/examples-advanced.md:566-568:javascript case 'exec': const result = await exec({ command: section.command }); return result.stdout;references/examples-advanced.md:581-583:javascript async fetchGitData(command) { const result = await exec({ command: `git ${command}` }); return result.stdout; }references/examples-advanced.md:742-744:javascript case 'exec': const result = await exec({ command: item.command }); return { output: result.stdout, exitCode: result.exitCode };references/extension-points.md:132-135:javascript const result = await exec({ command: `find ${dir} -name "${pattern}" -type f` });references/extension-points.md:509-513:javascript try { await exec({ ...[truncated 3216 chars]- Remediation
View remediation
Remediation Suggestions
- Do not construct shell commands from variable strings.
- Replace shell-based file reads, writes, copies, directory creation, cache deletion, and logging with Node.js filesystem APIs such as:
fs.promises.readFilefs.promises.copyFilefs.promises.mkdirfs.promises.unlinkfs.promises.appendFile
- Use a native HTTP client such as
fetchrather than invokingcurl. - Where an external process is necessary, use an argument-array API with shell processing disabled, for example
spawn(binary, args, { shell: false }). - Apply strict allowlists:
- Restrict HTTP methods to explicitly supported values.
- Parse endpoints with
URLand restrict protocols and destinations as required. - Validate paths against an approved workspace root using canonical paths.
- Restrict Git operations to known subcommands and validated arguments.
- Reject report types that permit arbitrary command execution.
- Remove the generic
execbatch processor andsection.commandfunctionality. Replace them with named, narrowly scoped operations. - If command execution is an essential extension point, require a trusted static command identifier mapped internally to fixed binaries and fixed argument schemas.
- Avoid logging complete headers, request bodies, options, errors, or state without redacting credentials and sensitive fields.
- Add adversarial tests covering command separators, quotes, substitutions, redirections, leading option characters, traversal sequences, and malicious filenames.
- Stop describing the affected snippets as production-ready until safe implementations and explicit trust-boundary documentation are provided.
