T09 · Insecure Skill Coding Practices
- Location
SKILL.md:238- Finding
Arbitrary Command Execution Through Unescaped Executable State File
- Content
View full analysis
"$_STATE_DIR/env.sh" <" ``` ### Technical Analysis The Skill serializes values into an executable shell script by placing them directly inside double-quoted assignments. It does not apply shell escaping before writing the values. Several persisted values originate from the repository environment or user input, including: - The repository path - The current branch name - The test command requested from the user when automatic detection fails - The lint command and other detected configuration A value containing a double quote followed by shell syntax can terminate the assignment and add a new command to `env.sh`. For example, a malicious test command conceptually shaped like: ```text "; touch /tmp/orchestrate-injected; # ``` would produce executable content resembling: ```bash export TEST_CMD=""; touch /tmp/orchestrate-injected; #" ``` The file is then repeatedly loaded with `source`, which evaluates all of its contents as shell code. This converts what should be passive state into a command-execution channel. This behavior exceeds the minimum privilege necessary for state pers ...[truncated 1406 chars]- Remediation
View remediation
"$_STATE_DIR/env.json" ``` 2. Load individual values with `jq -r` rather than `source`: ```bash _REPO_ROOT=$(jq -r '.repo_root' "$_STATE_DIR/env.json") TEST_CMD=$(jq -r '.test_cmd' "$_STATE_DIR/env.json") ``` 3. If shell serialization is unavoidable, encode every value using `printf '%q'` rather than interpolating it into quoted assignments: ```bash printf 'export TEST_CMD=%q\n' "$TEST_CMD" >> "$_STATE_DIR/env.sh" ``` 4. Validate user-provided commands. Prefer selecting an executable and argument array over accepting an unrestricted shell command string. 5. Restrict state-file permissions: ```bash umask 077 ``` 6. Create the state file atomically and verify it is a regular file owned by the current user before reading it. 7. Remove all uses of `source` for files containing repository-derived or user-derived values. ]]>
