T09 · Insecure Skill Coding Practices
- Location
scripts/init_sync.sh:449- Finding
Arbitrary Shell Command Injection Through eval-Based Command Execution
- Content
View full analysis
\"$agent_ws/SYNC.md\"" do_cmd "mkdir -p \"$local_agent_memory\"" do_cmd "_atomic_write \"$local_agent_memory/.agent_sync_version\" '$START_VERSION'" do_cmd "mkdir -p \"$local_agent_memory/.sync_snapshots\"" ``` ### Technical Analysis The `do_cmd` helper constructs shell commands as strings and executes them through `eval`. `eval` reparses its arguments as shell syntax, so quoting performed while creating the string does not provide a reliable security boundary. `MASTER_WS` may come directly from a positional command-line argument: ```bash elif [ -z "$MASTER_WS" ] && [ "${arg#--}" = "$arg" ]; then MASTER_WS="$arg" fi ``` It may also be derived from the editable Agent registry. No character validation, canonical path validation, or shell metacharacter rejection is performed before the value is interpolated into a command passed to `eval`. A value containing a quotation mark followed by shell syntax can terminate the intended quoted argument. Command separators, command substitutions, redirections, or pipelines can then be interpreted by the second shell parsing pass. The same unsafe execution pattern is used for writes and directory creation in downstream Agent workspaces. ### Attack Path 1. An attacker modifies `references/agent-registry.json`, influences a registry-generation source, or convinces a user to supply a crafted master-workspace argument. 2. The crafted path contains shell syntax that escapes the quoted argument used in a `do_c ...[truncated 1150 chars]- Remediation
View remediation
"$destination" fi } ``` 4. Reject control characters and unexpected shell metacharacters in identifiers and paths even after removing `eval`. 5. Validate all paths canonically before performing a write. 6. Add regression tests with spaces, quotes, semicolons, command substitutions, newlines, and redirection characters in all registry and command-line inputs. ]]>
