T06 · System Persistence
Error
- Location
- scripts/schedule.py:162
- Finding
- User crontab is replaced instead of safely updating Skill-owned entries## Vulnerability Details **File Location**: `scripts/schedule.py`, lines 162–210 **Vulnerability Type**: Destructive scheduled-task persistence management **Risk Level**: High ### Vulnerable Code ```python def update_crontab(tasks): lines = [ "# OpenClaw scheduled tasks", "# Edit: crontab -e", "# View: crontab -l", "", "SHELL=/bin/bash", "PATH=/usr/local/bin:/usr/bin:/bin:/home/wang/.npm-global/bin", "", "# Daily scheduled tasks" ] for task in tasks: if task.get('status') == '✅': time_parts = task['time'].split(':') hour = time_parts[0] minute = time_parts[1] weekday = task.get('weekday', '1-7') if weekday == '1-5': day_of_week = "1-5" elif weekday == '1-7' or weekday == '*': day_of_week = "*" else: day_of_week = weekday lines.append(f"{minute} {hour} * * {day_of_week} {RUN_TASK_SCRIPT} \"{task['name']}\"") crontab_content = '\n'.join(lines) + '\n' try: proc = subprocess.Popen( ['crontab', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) stdout, stderr = proc.communicate(crontab_content.encode()) ``` ### Technical Analysis The `crontab -` command installs its standard input as the complete crontab of the current operating-system user. The function constructs that input solely from tasks managed by this Skill. It does not read the existing crontab, preserve unrelated entries, or delimit Skill-owned records with managed-section markers. Consequently, every operation that calls `update_crontab()`—including adding, editing, enabling, disabling, toggling, or deleting a task—replaces the user's entire crontab. Scheduling persistence is necessar ...[truncated 1266 chars]
- Remediation
- ## Remediation Suggestions 1. Read the existing crontab with `crontab -l` before making changes. 2. Manage only a clearly delimited section, for example: ```text # BEGIN OPENCLAW SCHEDULE-MANAGER ... # END OPENCLAW SCHEDULE-MANAGER ``` 3. Replace only the content inside those markers and preserve every unrelated line byte-for-byte. 4. Back up the original crontab before installation and restore it if installation fails. 5. Show the proposed changes and require explicit user confirmation before the first cron modification. 6. Provide an uninstall or cleanup command that removes only the managed section. 7. Prefer a single fixed dispatcher entry rather than installing one cron record per user task. 8. Never require elevated privileges; modify only the invoking user's crontab.
