T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:153
- Finding
- Command Injection Through Direct Topic Interpolation in Bash Templates<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:153` and `SKILL.md:294` **Vulnerability Type**: Shell command injection **Risk Level**: High ### Vulnerable Code The same unsafe construction appears in both the single-platform and full-matrix generation workflows: ```bash TOPIC_SLUG=$(echo "{主题}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd '[:alnum:]-_\p{Han}') OUTPUT_DIR="$HOME/content-output/$(date +%Y-%m-%d)/${TOPIC_SLUG}" if [[ -d "$OUTPUT_DIR" ]]; then OUTPUT_DIR="${OUTPUT_DIR}-$(date +%H%M%S)" fi mkdir -p "$OUTPUT_DIR" ``` The matrix-generation variant is: ```bash TOPIC_SLUG=$(echo "{主题}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd '[:alnum:]-_\p{Han}') OUTPUT_DIR="$HOME/content-output/$(date +%Y-%m-%d)/${TOPIC_SLUG}/matrix" if [[ -d "$OUTPUT_DIR" ]]; then OUTPUT_DIR="$HOME/content-output/$(date +%Y-%m-%d)/${TOPIC_SLUG}-$(date +%H%M%S)/matrix" fi mkdir -p "$OUTPUT_DIR" ``` ### Technical Analysis The topic originates from user-controlled Skill arguments and is inserted directly into executable shell source. Although the placeholder is enclosed in double quotes, Bash still evaluates command substitutions such as `$(...)` and backtick substitutions inside double-quoted strings. The later `tr -cd` filtering does not mitigate this issue because command substitution is evaluated by Bash before the resulting text reaches the filtering pipeline. Consequently, sanitizing the generated slug occurs too late to prevent command execution. This issue affects both content-generation workflows that construct output directories from the topic. ### Attack Path 1. An attacker invokes the Skill with a topic containing Bash command-substitution syntax. 2. The Agent substitutes that topic into the documented Bash template. 3. The Agent executes the generated Bash block to construct the output path. 4. Bash evaluates the injected command substitution before executing `echo` and `tr`. 5. The injected command runs with the same oper ...[truncated 971 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Do not construct executable shell source by substituting user-controlled text into a command template. 1. Pass the topic as data through a positional argument or environment variable: ```bash USER_TOPIC="$1" TOPIC_SLUG="$( printf '%s' "$USER_TOPIC" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd '[:alnum:]_-' )" ``` 2. Keep all variable expansions quoted: ```bash OUTPUT_DIR="$HOME/content-output/$(date +%Y-%m-%d)/$TOPIC_SLUG" mkdir -p -- "$OUTPUT_DIR" ``` 3. Reject empty slugs after sanitization: ```bash if [[ -z "$TOPIC_SLUG" ]]; then printf '%s\n' 'Invalid topic: no safe slug characters remain.' >&2 exit 1 fi ``` 4. Explicitly reject path separators, control characters, newlines, shell metacharacters, and unexpected Unicode characters before use. 5. Prefer implementing slug generation through a fixed helper script or a non-shell API so that the topic can never become part of executable syntax. 6. Add regression tests using topics containing command substitutions, backticks, quotes, semicolons, newlines, path traversal sequences, and leading option characters. 7. Apply the same correction to both occurrences at lines 153 and 294. ]]>
