T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/ichiro-mind.sh:111
- Finding
- Arbitrary Python Code Execution Through CLI Argument Injection<![CDATA[ ## Vulnerability Details **File Location**: `scripts/ichiro-mind.sh:111-116` and `scripts/ichiro-mind.sh:131-139` **Vulnerability Type**: User-controlled arguments interpolated into dynamically evaluated Python source **Risk Level**: High ### Vulnerable Code ```bash python3 -c " from core import IchiroMind mind = IchiroMind() mind.remember('$content', '$category') print(f'✅ Remembered: {content[:50]}...') " ``` ```bash python3 -c " from core import IchiroMind mind = IchiroMind() results = mind.recall('$query') print(f'\\n🔍 Recall results for \\'$query\\':') for i, r in enumerate(results[:5], 1): print(f' {i}. [{r.category}] {r.content[:60]}...') " ``` ### Technical Analysis The `remember` and `recall` functions copy command-line arguments into shell variables and then interpolate those variables directly into source code passed to `python3 -c`. Shell quoting does not make these values safe as Python string literals. An argument containing a single quote can terminate the intended Python string and introduce additional Python statements. The injected Python executes with the same operating-system identity and environment as the `ichiro-mind` process. This affects: - Memory content through `$content` - Memory category through `$category` - Recall queries through `$query` For example, a malicious argument can conceptually terminate the string, invoke `__import__`, run an operating-system command, and comment out the remainder of the generated line. No validation or encoding prevents this transition from data to executable Python syntax. ### Attack Path 1. An attacker causes a user, automation workflow, or agent to invoke: - `ichiro-mind remember <attacker-controlled-content>`, or - `ichiro-mind recall <attacker-controlled-query>`. 2. The shell script assigns the supplied value to `content`, `category`, or `query`. 3. The value is inserted verbatim between single quotes in the source passed to `python3 -c`. 4. A crafted quote closes ...[truncated 951 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove all user-controlled interpolation into `python3 -c` source code. 2. Implement the CLI directly in Python with `argparse`, passing command-line values through `sys.argv` as data. 3. If the shell wrapper must remain, invoke a fixed Python module and pass arguments separately: ```bash python3 -m core_cli remember "$content" "$category" python3 -m core_cli recall "$query" ``` 4. In the Python entry point, read the values from `sys.argv` without using `eval`, `exec`, or generated source code. 5. Add regression tests containing single quotes, double quotes, newlines, semicolons, backslashes, Unicode, and Python-like payloads. 6. Run the CLI with the minimum required filesystem permissions and avoid exposing unrelated secrets through its environment. ]]>
