T09 · Insecure Skill Coding Practices
- Location
scripts/session-health-watchdog.sh:34- Finding
Python Code Injection Through Crafted Session Filenames
- Content
View full analysis
/dev/null || echo "unknown") ``` ### Technical Analysis The script derives `BASENAME` from a filesystem entry and directly embeds it inside Python source passed to `python3 -c`. Shell quoting around the command does not make the value safe once it becomes part of the generated Python program. A crafted `.jsonl` filename containing a single quote followed by valid Python syntax can terminate the intended Python string literal and introduce attacker-controlled statements. The injected statements execute whenever the watchdog examines a session file that meets the configured size threshold. Exploitation requires the attacker to be able to create or rename a sufficiently large `.jsonl` file under: ```text $HOME/.openclaw/agents/main/sessions ``` The recurring cron execution recommended by the project can provide a predictable execution trigger, but the cron mechanism itself is documented and is not a concealed persistence mechanism. ### Attack Path 1. The attacker obtains the ability to create or rename files in the OpenClaw sessions directory. 2. The attacker creates a `.jsonl` file of at least 5 MB, because only files meeting the session-size warning threshold reach the vulnerable Python invocation. 3. The file basename contains characters that close the Python string literal and inject valid Python code. 4. The user or the recommended scheduled watchdog invokes `session-health-watchdog.sh`. 5. The script discovers the crafted file, interpolates its basename into the `python3 -c` program, and ...[truncated 670 chars]- Remediation
View remediation
/dev/null`; log parsing failures without exposing sensitive data. 5. Add regression tests using filenames containing quotes, newlines, backslashes, and Python metacharacters. ]]>
