T09 · Insecure Skill Coding Practices
- Location
scripts/openclaw-backup.sh:36- Finding
Suppressed Copy Failures Can Produce Incomplete Backups Reported as Successful
- Content
View full analysis
/dev/null || true # 再拷贝隐藏文件 cp -a "$SOURCE_DIR"/.* "$BACKUP_PATH/" 2>/dev/null || true fi if [ $? -eq 0 ]; then echo "备份完成: $BACKUP_PATH" ``` ### Technical Analysis The fallback implementation suppresses diagnostics from both `cp` operations with `2>/dev/null` and unconditionally converts their exit status to success with `|| true`. The status evaluated by the subsequent `if [ $? -eq 0 ]` condition is therefore always zero in this branch, regardless of whether either copy operation failed. Failures can occur because of unreadable source files, insufficient destination capacity, filesystem errors, permission restrictions, or files changing during the backup. The script will nevertheless print a successful completion message and leave the partial destination in place. Using separate `*` and `.*` globs also makes the copy more fragile than copying the source directory contents through `"$SOURCE_DIR/."`. Dot-file glob behavior can vary between environments and may involve special directory entries on shells or platforms without protective behavior. ### Attack Path 1. The system does not have `rsync`, causing execution to enter the `cp` fallback branch. 2. An attacker with local influence over the source tree makes selected files unreadable, or an environmental condition such as insufficient disk capacity causes a copy operation to fail. 3. The affected `cp` command returns a nonzero status. 4. `2>/dev/null` hides the diagnostic, while `|| true` replaces the failure status with zero. 5. The final status check evaluates as successful and reports that the backup completed. 6. The user trusts the incomplete backup and may delete, replace, or damage the original ...[truncated 538 chars]- Remediation
View remediation
&2 exit 1 fi if ! cp -a "$SOURCE_DIR/." "$BACKUP_PATH/"; then echo "Error: backup failed" >&2 rm -rf -- "$BACKUP_PATH" exit 1 fi ``` Additional hardening measures: - Do not redirect copy errors to `/dev/null`; retain actionable diagnostics. - Check `mkdir` explicitly rather than continuing after destination creation fails. - For the `rsync` branch, explicitly test its exit status and clean up incomplete output on failure. - Consider copying into a temporary sibling directory and renaming it to the final timestamped name only after successful completion. - Optionally verify the result using an `rsync` dry run, file manifest, or checksums before reporting success. - Ensure cleanup paths remain constrained to a validated destination beneath `$HOME` before invoking `rm -rf`. ]]>
