T09 · Insecure Skill Coding Practices
- Location
SKILL.md:135- Finding
Command Injection Through Unsafe Shell Template Substitution
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 135–138; related unsafe path substitutions at lines 194 and 223
Vulnerability Type: Shell command injection
Risk Level: HighVulnerable Code
bash CONTENT=$(cat <<'BREWPAGE_EOF' {content} BREWPAGE_EOF )Related path substitutions:
bash (cd "{directory_path}" && zip -r "$TMPZIP" . -x '.git/*' '*/.git/*' '.env' '.env.*' '*/.env' '*/.env.*' 'node_modules/*' '*/node_modules/*' '.DS_Store' '*/.DS_Store' 'Thumbs.db' '.idea/*' '*/.idea/*' '.vscode/*' '*/.vscode/*' '.cache/*' '*/.cache/*' '*.map' '*.log')bash -F "archive=@{zip_file_path}")Technical Analysis
The Skill instructs the Agent to construct executable shell source by directly replacing placeholders with user-controlled content or filesystem paths. Shell quoting does not make textual source-code substitution safe.
For text publication, an attacker-controlled input containing a line exactly equal to
BREWPAGE_EOFcan terminate the heredoc before its intended endpoint. Subsequent input is then parsed as shell syntax rather than assigned toCONTENT.Directory and ZIP paths are likewise inserted inside double-quoted shell text. A path containing a double quote followed by shell metacharacters can escape the intended argument and introduce additional commands. These risks arise before
jqorcurlsafely processes the values.Attack Path
- An attacker supplies content to be published that includes the fixed heredoc terminator on its own line.
- The attacker places a shell command after that terminator.
- The Agent replaces
{content}in the documented Bash block with the supplied text. - The shell closes the heredoc at the attacker-provided terminator.
- The following text is interpreted and executed as shell commands under the Agent process's account.
An analogous path exists for a malicious directory or ZIP filename:
- The attacker creates or references a path containing qu ...[truncated 803 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not interpolate user-controlled values into generated shell source.
- Implement publishing in a fixed script that receives content and paths through positional parameters, standard input, or environment variables.
- For text content, write the content to a securely created temporary file or pass it through standard input, then invoke
jqwithout constructing a dynamic heredoc. - Pass paths as already-separated argument values, for example through
script.sh -- "$path", rather than inserting them into a command string. - Canonicalize and validate paths before use, while still relying on argument separation rather than validation alone.
- Avoid
eval, dynamically generated shell fragments, and fixed heredoc delimiters around untrusted data. - Add regression tests using content containing
BREWPAGE_EOF, command substitutions, quotes, semicolons, newlines, and filenames containing shell metacharacters. - If temporary files are used, create them with
mktemp, restrictive permissions, and cleanup traps.
