T09 · Insecure Skill Coding Practices
- Location
scripts/entropy_reduce.py:249- Finding
Permanent Note Deletion Without Per-File Confirmation or Recovery
- Content
View full analysis
Vulnerability Details
File Location:
scripts/entropy_reduce.py:249-258
Vulnerability Type: Unsafe destructive file operation
Risk Level: Mediumpython # 删除文件 if not dry_run and force: print("🗑️ 执行删除...") for item in self.stats["to_delete"]: try: Path(item["path"]).unlink() print(f" 删除:{item['path']}") except Exception as e: print(f" 删除失败 {item['path']}: {e}") elif not dry_run: print("💡 提示:使用 --force 参数执行删除")Technical Analysis
When the script is invoked with
--force, it permanently unlinks every file automatically placed inself.stats["to_delete"]. It does not request per-file approval, validate an approved deletion manifest, create a backup, or move files into a recoverable trash directory.The deletion candidates are selected through heuristic checks in
scripts/entropy_reduce.py:91-123andscripts/entropy_reduce.py:130-162. A journal can be selected when at least two conditions are met, including a failure to recognize an internal judgment, no connection inconnections.json, or a modification time older than 90 days. External notes can be selected merely because the keyword scanner does not recognize an internal judgment and no connection is recorded.These heuristics can misclassify valuable notes due to unrecognized wording, incomplete connection metadata, stale timestamps, or malformed connection data. This behavior also conflicts with
SKILL.md:210andSKILL.md:362, which state that deletion candidates should be presented to the user for confirmation.Attack Path
- A valuable note is stored under
data/journalordata/external. - The note does not contain one of the hardcoded judgment keywords, or its corresponding connection is absent from
connections.json. - For a journal note, another condition such as an age greater than 90 days is satisfied.
- The user or an agent invokes `p ...[truncated 983 chars]
- A valuable note is stored under
- Remediation
View remediation
Remediation Suggestions
- Keep report-only behavior as the default and require explicit approval of each candidate before any destructive operation.
- Accept an approved-file manifest generated from the dry-run report and delete only exact entries included in that manifest.
- Move candidates to a dedicated quarantine or trash directory rather than calling
unlink()immediately. - Record a deletion log containing the original path, quarantine path, reason, timestamp, and approval source.
- Resolve and validate every candidate path before acting:
- Resolve the data root and candidate with
Path.resolve(). - Verify that the candidate remains inside the intended data root.
- Reject symbolic links and non-regular files.
- Resolve the data root and candidate with
- Add a final interactive confirmation showing the exact number and paths of files to be affected.
- Improve classification by parsing structured note metadata rather than relying solely on substring keywords and modification times.
- Update the documentation so it precisely matches the implemented confirmation and recovery behavior.
