T09 · Insecure Skill Coding Practices
- Location
scripts/memory_backup.py:159- Finding
Arbitrary File Write Through Unsafe CLI Snapshot Restoration
- Content
View full analysis
10: print(f" ... 共 {len(names)} 个") return True for name in names: dst = target / name dst.parent.mkdir(parents=True, exist_ok=True) with zf.open(name) as src_f, open(dst, "wb") as dst_f: dst_f.write(src_f.read()) ``` ### Technical Analysis The restoration routine treats every ZIP member name as a safe path relative to `WORKSPACE`. It does not reject absolute paths, parent-directory components such as `../`, or paths whose canonical destination falls outside the workspace. For example, a member named `../../.ssh/authorized_keys` causes `target / name` to traverse outside `~/.qclaw/workspace`. Because the destination parent directories are created and the file is opened in write mode, the routine can overwrite any file writable by the current user. The CLI accepts a caller-provided archive path through: ```python restore_from_snapshot(Path(sys.argv[2])) ``` The archive is not authenticated or checked against a trusted manifest. In addition, each decompressed member is read completely into memory with `src_f.read()`, allowing a malicious archive to cause excessive memory consumption. ### Attack Path 1. An attacker prepares a ZIP archive containing a member such ...[truncated 1655 chars]- Remediation
View remediation
