T05 · Unauthorized Access and Privilege Escalation
- Location
dream-tools.sh:92- Finding
Unrestricted Atomic-Write Command Allows Arbitrary File Replacement
- Content
View full analysis
" [[ ! -f "$tmpfile" ]] && die "tmp 文件不存在:$tmpfile" # 若目标是 MEMORY.md,检查字符数上限 if [[ "$(realpath "$target" 2>/dev/null)" == "$(realpath "$MEMORY_MD" 2>/dev/null)" ]] || \ [[ "$target" == *"MEMORY.md" ]]; then local size size=$(wc -c < "$tmpfile" | tr -d ' ') if [[ $size -gt $MEMORY_HARD_LIMIT ]]; then die "写入中止:tmp 文件大小 ${size} 字符,超过硬上限 ${MEMORY_HARD_LIMIT}。请先压缩内容。" fi log "MEMORY.md 写入校验通过:${size}/${MEMORY_HARD_LIMIT} 字符" fi ensure_dir "$target" # mv 在同一文件系统上是原子操作 mv "$tmpfile" "$target" log "原子写入完成:$target" } ``` ### Technical Analysis The `--atomic-write` operation accepts both its source and destination from command-line arguments. It does not verify that the canonical destination is located under either `DREAM_VAULT_PATH` or `OPENCLAW_WORKSPACE`. The `realpath` comparison only determines whether to apply the `MEMORY.md` size limit. It is not an access-control check. For any destination that does not end in `MEMORY.md`, the script creates the destination's parent directory and moves the supplied file over the destination. Consequently, any component or user able to invoke this helper can replace any file writable by the OpenClaw operating-system account. This directly contradicts the security claim in `readme.md` that all file operations are strictly scoped to the vault and workspace. Path and symlink behavior also require hardening. A lexical prefix check alone would not be sufficient because traversal components and symlinks could redirect writes outside an approved root. ### Attack Path 1. Th ...[truncated 1429 chars]- Remediation
View remediation
