T09 · Insecure Skill Coding Practices
Warning
- Location
- fix_feishu_cache.sh:5
- Finding
- Privileged and Unsafe Replacement of Globally Installed OpenClaw Source Code<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:21` and `fix_feishu_cache.sh:5-9` **Vulnerability Type**: Unsafe privileged file replacement **Risk Level**: Medium The documentation instructs the user to execute the entire bundled script with `sudo`: ```bash # 1.sudo bash fix_feishu_cache.sh ``` The privileged script then backs up and directly overwrites a source file in the global OpenClaw installation: ```bash PROBE_FILE="/usr/local/lib/node_modules/openclaw/extensions/feishu/src/probe.ts" # 备份原文件 cp "$PROBE_FILE" "${PROBE_FILE}.bak" # 创建带缓存的版本 cat > "$PROBE_FILE" << 'EOF' ``` ### Technical Analysis Executing the complete script with `sudo` grants every command in the script unrestricted root privileges, although the legitimate task only requires narrowly scoped permission to update one installed file. The replacement operation is not implemented defensively: - The script does not use `set -euo pipefail`, so it may continue after a failed backup. - It does not verify that the target exists, is a regular file, and is not a symbolic link. - It does not check whether the installed OpenClaw version is compatible with the replacement source. - It overwrites any existing `.bak` file, potentially destroying the last usable backup. - It writes directly to the destination rather than validating a temporary file and atomically installing it. - It does not validate the resulting TypeScript file before reporting success. - It asks the user to trust and run the entire package script as root rather than applying only the necessary operation with elevated privileges. No evidence was found that the current script intentionally executes an external payload, exfiltrates information, establishes persistence, or contains hidden malicious behavior. The vulnerability arises from excessive privilege and unsafe file replacement practices. ### Attack Path 1. A user follows the instruction in `SKILL.md:21` and runs the bundled shell script with `sudo`. 2. ...[truncated 1695 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Enable strict shell failure handling at the beginning of the script: ```bash set -euo pipefail ``` 2. Do not instruct users to execute the entire script with `sudo`. Perform preparation and validation as an unprivileged user, then elevate only the final narrowly scoped installation command. 3. Validate the canonical destination before modification: - Confirm that the expected OpenClaw installation and version are present. - Require the target to be a regular file. - Reject symbolic links and unexpected ownership or permissions. - Resolve and verify the canonical path remains under the intended OpenClaw installation directory. 4. Create a non-clobbering backup with restrictive permissions and a unique timestamp or use `cp --backup=numbered`. Abort immediately if backup creation fails. 5. Write the replacement to a securely created temporary file rather than directly redirecting into the installed file: ```bash temp_file="$(mktemp)" trap 'rm -f "$temp_file"' EXIT ``` 6. Validate the generated source before installation using the applicable TypeScript compiler, formatter, or OpenClaw test command. 7. Install the validated file atomically with appropriate ownership and permissions, for example by using a narrowly scoped privileged `install` or `mv` operation. 8. Verify the installed OpenClaw version or the expected hash/content of the original `probe.ts` before applying the change. Abort on unsupported versions rather than replacing unknown source code. 9. Report success only after backup, validation, installation, and post-installation verification all complete successfully. 10. Prefer distributing a reviewed version-specific patch and applying it through the application's supported extension, update, or package-management mechanism instead of replacing globally installed source code. ]]>
