T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/diagnose.sh:151
- Finding
- Execution of an Untrusted Workspace Log-Rotation Script<![CDATA[ ## Vulnerability Details **File Location**: `scripts/diagnose.sh`, lines 151–153 **Vulnerability Type**: Execution of a mutable external script without trust validation **Risk Level**: Medium ```bash if $FIX && [ -f "$OC_WORKSPACE/scripts/log_rotate.sh" ]; then bash "$OC_WORKSPACE/scripts/log_rotate.sh" >/dev/null 2>&1 && fixed "Logs rotated" fi ``` ### Technical Analysis When invoked with `--fix`, the diagnostic executes `~/.openclaw/workspace/scripts/log_rotate.sh` if the OpenClaw log directory exceeds 500 MB. This script is outside the audited Skill package and may reside in a user-modifiable workspace. Before execution, the code only confirms that the path is a regular file. It does not validate: - The file's owner or group - Whether its permissions permit modification by untrusted users - Its canonical path or possible symbolic-link resolution - Its provenance or relationship to this Skill - Its integrity through a pinned cryptographic hash - Whether the file changed between validation and execution Consequently, the diagnostic crosses a local trust boundary by treating a mutable workspace file as executable trusted code. Quoting the path prevents argument splitting but does not mitigate malicious contents within the script. ### Attack Path 1. An attacker, compromised process, malicious extension, or other actor with write access to `~/.openclaw/workspace/scripts/` creates or replaces `log_rotate.sh`. 2. The attacker inserts arbitrary shell commands into that file. 3. The OpenClaw log directory reaches the script's failure threshold of at least 500 MB. 4. A user or agent invokes: ```bash bash scripts/diagnose.sh --fix ``` 5. The diagnostic launches the attacker-controlled file with `bash`. 6. The injected commands execute under the identity and environment of the account running the diagnostic. This path requires local write access to the workspace and explicit use of `--fix`; it is not triggered during the documented read-on ...[truncated 783 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Do not execute a workspace-provided repair script.** Bundle a reviewed log-rotation implementation inside the Skill package and invoke it using a path derived from the diagnostic script's trusted installation directory: ```bash SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" bash "$SCRIPT_DIR/log_rotate.sh" ``` 2. **Prefer implementing rotation directly** in `diagnose.sh` with explicit file-selection, retention, and size limits. Avoid evaluating generated shell text or invoking scripts from mutable workspace locations. 3. **If external delegation is unavoidable, validate the target before execution:** - Resolve and verify its canonical path. - Reject symbolic links. - Require ownership by the invoking user or a designated trusted administrator. - Reject files writable by group or other users. - Compare the file against a pinned cryptographic hash or signed manifest. - Minimize time-of-check/time-of-use exposure. 4. **Request explicit confirmation** before executing any external repair component and display the exact resolved path. 5. **Run repair operations with minimum privileges.** Use a restricted environment and avoid inheriting unnecessary credentials or sensitive environment variables. ]]>
