T06 · System Persistence
Warning
- Location
- install.sh:203
- Finding
- Installer Adds Recurring Cron Jobs by Default<![CDATA[ ## Vulnerability Details **File Location**: `install.sh:203-215` **Additional Location**: `scripts/install.sh:43-63` **Vulnerability Type**: Persistent scheduled execution **Risk Level**: Medium ### Vulnerable Code ```bash # 5. 配置 cron 任务 log_step "配置 cron 任务..." GC_SCRIPT="$SCRIPT_DIR/scripts/memory-gc.sh" REFLECTION_SCRIPT="$SCRIPT_DIR/scripts/nightly-reflection.sh" LOG_DIR="$HOME/.openclaw/logs" mkdir -p "$LOG_DIR" # 检查 cron 任务是否已存在 if crontab -l 2>/dev/null | grep -q "agent-memory-system"; then log_info "cron 任务已存在,跳过" else # 添加 cron 任务 ( crontab -l 2>/dev/null || true echo "# agent-memory-system - 每周日凌晨执行 GC" echo "0 0 * * 0 $GC_SCRIPT >> $LOG_DIR/memory-gc.log 2>&1" echo "# agent-memory-system - 每晚反思" echo "45 23 * * * $REFLECTION_SCRIPT >> $LOG_DIR/nightly-reflection.log 2>&1" ) | crontab - log_info "✓ cron 任务已配置" fi ``` The secondary installer presents the configuration as optional, but defaults to enabling it: ```bash # 5. 配置 crontab(可选) echo "⏰ 配置定时任务..." read -p "是否配置自动 GC 和反思任务?(y/n, 默认:y): " CONFIG_CRON CONFIG_CRON="${CONFIG_CRON:-y}" if [[ "$CONFIG_CRON" == "y" || "$CONFIG_CRON" == "Y" ]]; then # 检查 crontab 是否已存在相关配置 if crontab -l 2>/dev/null | grep -q "memory-gc.sh"; then echo "⚠️ 检测到已有 memory-gc.sh 配置,跳过" else # 添加 GC 任务(每周日 00:00) (crontab -l 2>/dev/null | grep -v "memory-gc.sh" || true; echo "0 0 * * 0 $SCRIPT_DIR/memory-gc.sh") | crontab - echo "✅ 已添加每周 GC 任务" fi if crontab -l 2>/dev/null | grep -q "nightly-reflection.sh"; then echo "⚠️ 检测到已有 nightly-reflection.sh 配置,跳过" else # 添加反思任务(每天 23:45) (crontab -l 2>/dev/null | grep -v "nightly-reflection.sh" || true; echo "45 23 * * * $SCRIPT_DIR/nightly-reflection.sh") | crontab - echo "✅ 已添加每日反思任务" fi else echo "⏭️ 跳过 crontab 配置,可以手动添加" fi ``` ### Technical Analysis The primary installer modifies the invoking ...[truncated 2161 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not modify the crontab in the default installation path. 2. Require explicit opt-in and default the prompt to `N`. 3. Display the exact cron entries and their execution frequency before requesting approval. 4. Add a noninteractive flag such as `--enable-cron`; without that flag, skip persistence configuration. 5. Check that `crontab` is available immediately before every use and handle failure without partially completing installation. 6. Install scheduled scripts into a stable, user-owned directory and reject scripts that are writable by other users. 7. Provide dedicated `--status`, `--disable-cron`, and `--uninstall` operations that identify entries precisely rather than relying only on broad substring matching. 8. Document that modifying or replacing the installed scripts changes the code cron will execute. ]]>
