T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/context-snapshot.js:77
- Finding
- Snapshot Clear Operation Retains Sensitive Context## Vulnerability Details **File Location**: `scripts/context-snapshot.js`, lines 77-81 **Vulnerability Type**: Improper deletion of sensitive information **Risk Level**: Medium ### Vulnerable Code ```javascript else if (cmd === 'clear') { const snapshot = loadSnapshot(); if (snapshot) { saveSnapshot(snapshot.task, snapshot.findings, snapshot.pending, snapshot._clearedAt = new Date().toISOString()); } console.log(JSON.stringify({ ok: true, message: 'Snapshot cleared.' })); } ``` ### Technical Analysis The `clear` command does not delete the snapshot or sanitize its sensitive fields. Instead, it loads the existing snapshot and writes the original `task`, `findings`, and `pending` values back to the same file. The clearing timestamp is passed as the `lastError` argument, so the rewritten snapshot still contains the data that the user intended to remove. The command then unconditionally reports `"Snapshot cleared."`, creating a false assurance that deletion succeeded. Because snapshots are explicitly designed to contain high-fidelity raw findings and may also contain error details, retained content can include sensitive project information. ### Attack Path 1. Snapshot support is enabled. 2. The agent invokes `save` with sensitive task context, findings, pending work, or error information. 3. The user or agent invokes `node scripts/context-snapshot.js clear`. 4. The script reloads the snapshot and rewrites its sensitive contents instead of deleting them. 5. A later invocation of `node scripts/context-snapshot.js load`, or direct access by another process running as the same operating-system user, recovers the supposedly cleared information. ### Impact Assessment This issue causes unintended local retention and disclosure of snapshot content. The affected scope is the project-specific snapshot file under the operating system's temporary directory. The flaw does not grant elevated privileges, bypas ...[truncated 315 chars]
- Remediation
- ## Remediation Suggestions Implement `clear` by deleting the snapshot file with `unlinkSync` or its asynchronous equivalent rather than rewriting the existing values. Handle deletion errors explicitly and report success only after deletion completes. Example: ```javascript import { readFileSync, writeFileSync, existsSync, chmodSync, unlinkSync } from 'fs'; // ... else if (cmd === 'clear') { try { if (existsSync(SNAPSHOT_FILE)) { unlinkSync(SNAPSHOT_FILE); } console.log(JSON.stringify({ ok: true, message: 'Snapshot cleared.' })); } catch (error) { console.error(JSON.stringify({ ok: false, error: 'Failed to clear snapshot.' })); process.exit(1); } } ``` Add automated tests verifying that: 1. Saving and then clearing a snapshot removes the file. 2. `load` returns no snapshot after clearing. 3. Deletion failures produce a nonzero exit status and do not claim success. 4. Repeated `clear` operations are safely idempotent.
