T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/restore.sh:78
- Finding
- Restore Safety Snapshot Copies API Secrets Without Explicit Opt-In<![CDATA[ ## Vulnerability Details **File Location**: `scripts/restore.sh:78-82` **Vulnerability Type**: Secret exposure caused by violation of the documented opt-in boundary **Risk Level**: High ### Vulnerable Code ```bash for src_file in openclaw.json .env; do if [[ -f "$HOME/.openclaw/${src_file}" ]]; then cp -- "$HOME/.openclaw/${src_file}" "${PRE_SNAP}/${src_file}" echo " saved: $src_file" fi done ``` ### Technical Analysis The restore workflow unconditionally includes `$HOME/.openclaw/.env` in the pre-restore safety snapshot whenever that file exists. This behavior does not check whether `.env` was explicitly included in the configured `backupPaths`. This conflicts with the documented security boundary in `SKILL.md`, which states that `.env` contains API keys, is excluded by default, and must be backed up only through an explicit opt-in. Running a restore therefore causes a secret-bearing file to be copied to the backup destination even when the user deliberately omitted it from normal backups. For SMB operation, `PRE_SNAP` is located below the mounted NAS backup directory. The copied `.env` can consequently enter NAS snapshots, replication systems, external backup media, or retention processes. The copy also preserves no explicit restrictive destination mode. ### Attack Path 1. The user keeps API keys in `$HOME/.openclaw/.env`. 2. The user does not add `.env` to `backupPaths`, relying on the documented default exclusion. 3. An SMB backup share is mounted and contains a snapshot eligible for restoration. 4. The user invokes `restore.sh` and confirms the restore. 5. The script creates a pre-restore safety snapshot on the NAS. 6. The script copies the live `.env` into that snapshot without a separate warning or opt-in check. 7. A NAS user, compromised NAS account, replication target, or other principal with snapshot access obtains the API keys. ### Impact Assessment This issue can disclose every secret stored in `.env`, ...[truncated 542 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Include `.env` in a safety snapshot only if its normalized path is explicitly present in `backupPaths`. 2. Add a dedicated configuration option such as `includeSecretsInSafetySnapshots`, defaulting to `false`. 3. Before copying `.env`, display a separate warning identifying the destination and require explicit confirmation. 4. Create secret-bearing destination files with restrictive permissions, such as mode `0600`, where the destination filesystem supports Unix permissions. 5. Document how NAS snapshots, replication, encryption at rest, and retention apply to secret-bearing backups. 6. Consider excluding `.env` from automated safety snapshots entirely and instead instruct users to recover API keys from a dedicated secrets manager. Example hardened logic: ```bash include_env=false while IFS= read -r configured_path; do expanded_path="${configured_path/#\~/$HOME}" if [[ "$expanded_path" == "$HOME/.openclaw/.env" ]]; then include_env=true break fi done < <(jq -r '.backupPaths[]' "$CONFIG") if [[ -f "$HOME/.openclaw/openclaw.json" ]]; then cp -- "$HOME/.openclaw/openclaw.json" "$PRE_SNAP/openclaw.json" fi if [[ "$include_env" == "true" && -f "$HOME/.openclaw/.env" ]]; then install -m 600 -- "$HOME/.openclaw/.env" "$PRE_SNAP/.env" fi ``` ]]>
