T09 · Insecure Skill Coding Practices
Warning
- Location
scripts/set_agent_model.sh:46- Finding
Predictable Temporary File Enables Symlink-Based File Overwrite and Configuration Corruption
- Content
View full analysis
/tmp/openclaw.json.tmp mv /tmp/openclaw.json.tmp "$CONFIG_FILE" ``` ### Technical Analysis The script writes generated configuration data to the fixed, globally predictable path `/tmp/openclaw.json.tmp`. Files in `/tmp` can generally be created by any local user. The script neither creates this file securely nor verifies that it is a regular file owned by the executing user. A local attacker can create `/tmp/openclaw.json.tmp` as a symbolic link before the script runs. Shell output redirection follows symbolic links, so the `jq` output will overwrite the symlink target using the script user's privileges. The subsequent `mv` operation can also replace the OpenClaw configuration path with the attacker-created symbolic link. The vulnerability becomes security-relevant when the script is executed by a privileged account or an account with access to files unavailable to the attacker. ### Attack Path 1. A local attacker predicts the fixed temporary path `/tmp/openclaw.json.tmp`. 2. The attacker creates that path as a symbolic link to a file writable by the account expected to run the script. 3. A more privileged user or service invokes `scripts/set_agent_model.sh`. 4. The shell follows the symbolic link during output redirection and truncates or overwrites its target with generated JSON. 5. The `mv` command then moves the attacker-created symbolic link over `/data/.openclaw/openclaw.json`. 6. The OpenClaw configuration may consequently become corrupted or remain redirected to another file, disrupting subsequent configuration operations. ### Impact Assessment A successful attacker can cause arbit ...[truncated 667 chars]- Remediation
View remediation
"$TMP_FILE" jq empty "$TMP_FILE" chmod --reference="$CONFIG_FILE" "$TMP_FILE" chown --reference="$CONFIG_FILE" "$TMP_FILE" mv -- "$TMP_FILE" "$CONFIG_FILE" trap - EXIT ``` Additional hardening measures should include: 1. Refuse to operate if the configuration path itself is a symbolic link unless that behavior is explicitly required. 2. Restrict access to the configuration directory to trusted users. 3. Use a cleanup trap so interrupted executions do not leave temporary files behind. 4. Check every filesystem operation for failure. 5. Preserve configuration ownership and permissions when atomically replacing the file. ]]>
