T06 · System Persistence
Error
- Location
- main.js:254
- Finding
- Automatic Remote Crontab Replacement Creates Persistent Execution<![CDATA[ ## Vulnerability Details **File Location**: `main.js:254-263` **Vulnerability Type**: Scheduled-task persistence and destructive crontab replacement **Risk Level**: Critical ### Vulnerable Code ```js // Sync cron jobs async function syncCron(host, user, key) { log('Syncing cron jobs...', 'cyan'); try { const result = await execCmd('crontab -l 2>/dev/null || echo ""'); const crons = result.stdout; if (crons.trim()) { // Save to remote const cmd = `ssh ${user}@${host} "echo '${crons.replace(/'/g, "'\\''")}' | crontab -"`; await execCmd(cmd); log('Cron jobs synced', 'green'); } else { log('No cron jobs to sync', 'gray'); } ``` ### Technical Analysis The migration reads the invoking user's entire local crontab and pipes it to `crontab -` on the target. This is a persistence mechanism because every transferred entry can continue executing after the migration process terminates and across future login sessions or reboots. The operation is performed automatically after the general migration confirmation. Users are not shown the cron entries, asked for separate consent, or allowed to select only OpenClaw-related jobs. In addition, `crontab -` replaces the target user's complete existing crontab rather than safely merging OpenClaw-specific entries. The cron content is also embedded in a shell command. Replacing single quotes alone is not sufficient protection in the surrounding nested shell context. Shell substitutions and other metacharacters in cron data may be interpreted while constructing or executing the SSH command. Although cron migration is disclosed in `README.md` and `SKILL.md`, transferring every user job exceeds the minimum scope necessary to migrate OpenClaw. Only explicitly identified OpenClaw jobs should be considered. ### Attack Path 1. An attacker, compromised application, or untrusted installer places a malicious entry in the source user's crontab. 2. The user starts the ...[truncated 970 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Make cron migration disabled by default and require a separate, explicit confirmation. - Display every proposed cron entry before installation. - Transfer only entries positively identified as belonging to OpenClaw. - Back up the target crontab before making any changes. - Merge approved entries with the existing target crontab instead of replacing it. - Transfer cron content over standard input using `spawn()` or `execFile()` with fixed argument arrays rather than interpolating it into a shell command. - Validate cron syntax and reject command substitutions, unexpected executables, unsafe paths, and unrelated jobs. - Provide a rollback procedure and report exactly which entries were installed. ]]>
