T09 · Insecure Skill Coding Practices
- Location
scripts/restore.sh:257- Finding
Untrusted backup archives can install and execute attacker-controlled scripts
- Content
View full analysis
{ if (err) return json(res, 400, { error: err.message }); if (!file.filename.endsWith('.tar.gz')) return json(res, 400, { error: 'Only .tar.gz files accepted' }); const dest = path.join(BACKUP_DIR, path.basename(file.filename)); fs.writeFileSync(dest, file.data); fs.chmodSync(dest, 0o600); return json(res, 200, { message: 'Upload successful', filename: file.filename, size: fmt(file.data.length) }); }); } ``` ```bash # scripts/restore.sh:43-51 WORK_DIR="/tmp/openclaw-restore-$$" mkdir -p "$WORK_DIR" trap "rm -rf $WORK_DIR" EXIT info "Extracting archive..." tar -xzf "$ARCHIVE" -C "$WORK_DIR" BACKUP_DIR=$(find "$WORK_DIR" -maxdepth 1 -name "openclaw-backup_*" -type d | head -1) [ -z "$BACKUP_DIR" ] && error "Invalid archive: no openclaw-backup_* directory found" ``` ```bash # scripts/restore.sh:257-269 if [ -d "${BACKUP_DIR}/scripts" ] && [ -n "$(ls -A ${BACKUP_DIR}/scripts 2>/dev/null)" ]; then info "Restoring scripts..." if $DRY_RUN; then dryrun "copy scripts → ${OPENCLAW_HOME}/" else for f in "${BACKUP_DIR}/scripts/"*; do fname=$(basename "$f") cp "$f" "${OPENCLAW_HOME}/${fname}" chmod +x "${OPENCLAW_HOME}/${fname}" done info " scripts restored ($(ls ${BACKUP_DIR}/scripts | tr '\n' ' '))" fi fi ``` ```bash # scripts/restore.sh:286-291 if ! $DRY_RUN; then echo "" info "Starting OpenClaw Gateway..." if [ -f "${OPENCLAW_HOME}/start-gateway.sh" ]; then bash "${OPENCLAW_HOME}/start-gateway.sh" & ``` ### Technical Analysis The authenticated upload endpoint accepts a ...[truncated 1806 chars]- Remediation
View remediation
