T06 · System Persistence
- Location
- setup.js:69
- Finding
- Setup Automatically Installs Persistent Scheduled Jobs<![CDATA[ ## Vulnerability Details **File Location**: `setup.js:69-96` **Vulnerability Type**: Automatic cross-session persistence through cron and Windows Task Scheduler **Risk Level**: High ### Vulnerable Code ```js function setupLinux(scripts) { const base=path.resolve(scripts,'..'); const nodePath=process.execPath; // Use actual Node binary, NVM-safe const crons=[ `*/30 * * * * cd ${base} && ${nodePath} scripts/ingest.js >> /tmp/secondmind-ingest.log 2>&1`, `15 */6 * * * cd ${base} && ${nodePath} scripts/consolidate.js >> /tmp/secondmind-consolidate.log 2>&1`, `0 3 * * * cd ${base} && ${nodePath} scripts/archive.js >> /tmp/secondmind-archive.log 2>&1`, `45 */6 * * * cd ${base} && ${nodePath} scripts/initiative.js >> /tmp/secondmind-initiative.log 2>&1`, ]; try { let ex=''; try{ex=execSync('crontab -l 2>/dev/null',{encoding:'utf8'})}catch{} const filtered=ex.split('\n').filter(l=>!l.includes('secondmind-')&&!l.includes('secondmind')).filter(l=>l.trim()).join('\n'); const nc=filtered+'\n\n# ── SecondMind ──\n'+crons.join('\n')+'\n'; fs.writeFileSync('/tmp/secondmind-crontab',nc); execSync('crontab /tmp/secondmind-crontab'); fs.unlinkSync('/tmp/secondmind-crontab'); console.log(` ✅ ${crons.length} cron jobs installed`); } catch(e) { console.error(' ❌',e.message); } } function setupWin(scripts) { const node=process.execPath; [{name:'Eigen-Ingest',s:'ingest.js',m:30},{name:'Eigen-Consolidate',s:'consolidate.js',m:360},{name:'Eigen-Archive',s:'archive.js',d:'03:00'},{name:'Eigen-Initiative',s:'initiative.js',m:360}].forEach(t=>{ const cmd=`"${node}" "${path.join(scripts,t.s)}"`; try{execSync(`schtasks /Delete /TN "${t.name}" /F 2>nul`,{stdio:'ignore'})}catch{} try{ if(t.d) execSync(`schtasks /Create /TN "${t.name}" /TR ${cmd} /SC DAILY /ST ${t.d} /F`); else execSync(`schtasks /Create /TN "${t.name}" /TR ${cmd} /SC MINUTE /MO ${t.m} /F`); console.log(` ✅ ${t.name}`); }cat ...[truncated 1927 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Make scheduling optional and separate it from database initialization, for example: - `node setup.js` - `node setup.js --install-schedule` 2. Display every proposed cron entry or scheduled task and require explicit confirmation before installation. 3. Add a documented `--remove-schedule` operation that removes only tasks created by the current installation. 4. Mark entries with a unique installation identifier and avoid deleting unrelated lines merely because they contain the word `secondmind`. 5. Default to manual or foreground execution where persistent automation is not explicitly requested. 6. Ensure scheduled jobs run with the least-privileged user and a restricted environment. ]]>
