T09 · Insecure Skill Coding Practices
- Location
dream-tools.sh:454- Finding
Arbitrary Python Code Execution Through Unvalidated Timestamp State
- Content
View full analysis
/dev/null; then hours_since=$(python3 -c " from datetime import datetime last = datetime.strptime('$last_review', '%Y-%m-%d %H:%M') diff = datetime.now() - last print(int(diff.total_seconds() / 3600)) " 2>/dev/null || echo "-") fi fi ``` ### Technical Analysis The contents of `meta/last-review.txt` are read into `last_review` and interpolated directly into source code passed to `python3 -c`. Shell quoting does not make this safe because the value is inserted inside a Python string literal. A malicious timestamp containing a single quote followed by valid Python statements can terminate the intended string and inject arbitrary Python code. For example, a crafted value can import `os` and invoke system commands before commenting out the remainder of the generated line. The script neither validates the timestamp format before interpolation nor passes the value through a non-code channel such as a command-line argument or environment variable. The exception fallback does not prevent exploitation because injected statements execute before a later parsing error is handled by the shell. ### Attack Path 1. An attacker, another local process, or an agent operation modifies: `DREAM_VAULT_PATH/meta/last-review.txt`. 2. The attacker supplies content designed to terminate the Python string and insert Python statements. 3. The user or agent invokes: ```bash dream-tools.sh --status ``` 4. `cmd_status` places the malicious file content directly into the program passed to `python3 -c`. 5. Python executes the injected statements with ...[truncated 541 chars]- Remediation
View remediation
