T09 · Insecure Skill Coding Practices
- Location
snapshot.py:34- Finding
Snapshot Tag Path Traversal Allows Memory Artifacts to Be Written Outside the Snapshot Directory
- Content
View full analysis
2 and sys.argv[1] == "take": take_snapshot(sys.argv[2] if len(sys.argv) > 2 else None) ``` Files are subsequently copied to the derived directory: ```python if CONV_LOG.exists(): shutil.copy2(CONV_LOG, snap_dir / "conversation-log.md") if TOPIC_PATH.exists(): shutil.copy2(TOPIC_PATH, snap_dir / "topic-index.json") if STUB_PATH.exists(): shutil.copy2(STUB_PATH, snap_dir / "stub-index.md") if FTS5_DB.exists(): db_dest = snap_dir / "memory-index.db" shutil.copy2(FTS5_DB, db_dest) ``` ### Technical Analysis The `tag` value is used as a path component without validation or containment checking. Python's `pathlib` permits both traversal components such as `../` and absolute paths: - A tag such as `../../exported-memory` escapes `SNAPSHOT_DIR`. - An absolute tag such as `/tmp/exported-memory` causes the intended base directory to be discarded. - `mkdir(parents=True, exist_ok=True)` creates the attacker-selected directory hierarchy. - `shutil.copy2()` writes fixed-name conversation and index artifacts into that location and may overwrite existing same-named files. This is a local path traversal vulnerability. Exploitation requires the ability to invoke the script with a chosen snapshot tag, directly or through another component that exposes this argument. ### Attack Path 1. An attacker or untrusted caller obtains the ability to supply the argument to `snapshot.py take`. ...[truncated 1421 chars]- Remediation
View remediation
