T09 · Insecure Skill Coding Practices
- Location
scripts/restore.sh:23- Finding
Arbitrary Python Code Execution Through Unsanitized Job ID
- Content
View full analysis
/dev/null | python3 -c " import json, sys text = sys.stdin.read() start = text.index('{') data = json.loads(text[start:]) for job in data.get('jobs', data): if job['id'].startswith('$JOB_ID') or job['id'] == '$JOB_ID': print(f' name: {job.get(\"name\")}') print(f' session: {job.get(\"sessionTarget\")}') print(f' kind: {job.get(\"payload\",{}).get(\"kind\")}') d = job.get('delivery', {}) print(f' mode: {d.get(\"mode\")}') print(f' channel: {d.get(\"channel\")}') print(f' to: {d.get(\"to\")}') print(f' accountId: {d.get(\"accountId\")}') break " ``` ### Technical Analysis The first positional argument is assigned to `JOB_ID` and interpolated directly into the source code supplied to `python3 -c`: ```python if job['id'].startswith('$JOB_ID') or job['id'] == '$JOB_ID': ``` Shell quoting protects the later `openclaw cron edit "$JOB_ID"` invocation from ordinary shell argument injection, but it does not protect the generated Python program. A job ID containing quote characters and Python syntax can terminate the intended string literal and inject additional Python expressions or statements. The injected Python runs with the same operating-system identity and environment as the user executing `restore.sh`. No job-ID format validation, escaping, or argument-based transfer into Python is performed. ### Attack Path 1. An attacker supplies or recommends a maliciously crafted job ID to a user or automation agent. 2. The user invokes `restore.sh` with that value as its first argument. 3 ...[truncated 969 chars]- Remediation
View remediation
/dev/null | python3 -c ' import json import sys job_id = sys.argv[1] text = sys.stdin.read() start = text.index("{") data = json.loads(text[start:]) for job in data.get("jobs", data): if job.get("id") == job_id: print(f" name: {job.get('name')}") print(f" session: {job.get('sessionTarget')}") print(f" kind: {job.get('payload', {}).get('kind')}") delivery = job.get("delivery", {}) print(f" mode: {delivery.get('mode')}") print(f" channel: {delivery.get('channel')}") print(f" to: {delivery.get('to')}") print(f" accountId: {delivery.get('accountId')}") break ' "$JOB_ID" ``` Additional hardening should include: 1. Validate `JOB_ID` against the exact identifier syntax accepted by OpenClaw. 2. Use exact identifier equality rather than ambiguous prefix matching. 3. Reject empty, malformed, or multiple-match identifiers before making changes. 4. Prefer a standalone Python script or a structured JSON-processing tool over dynamically generated source. 5. Test the script with quotes, backslashes, newlines, and Python metacharacters to prevent regression. ]]>
