T09 · Insecure Skill Coding Practices
- Location
scripts/execute_plan.py:78- Finding
Caller-Controlled Log Path Allows Arbitrary File Deletion During Dry-Run
- Content
View full analysis
Vulnerability Details
File Location:
scripts/execute_plan.py, lines 78-81
Vulnerability Type: Arbitrary file deletion through an unrestricted log path
Risk Level: HighVulnerable Code
python plan = load_json(args.plan) log_path = Path(args.log) if args.log else Path(f"organize-log_{now_iso().replace(':', '').replace('-', '')}.jsonl") if log_path.exists(): log_path.unlink()Technical Analysis
The
--logargument is fully controlled by the caller. If the selected path already exists, the executor unconditionally deletes it withPath.unlink().The deletion occurs regardless of whether
--applywas specified. Consequently, the documented dry-run mode is not read-only and can perform a destructive filesystem operation. The path is not constrained to the expected report directory, checked for an approved filename, or verified as an existing application-generated log.After deletion, the program writes execution-log records to the same path. This may recreate the deleted file with unrelated JSONL data, resulting in destructive replacement rather than merely removing it.
Attack Path
- An attacker, unsafe automation, or misleading generated command supplies a writable, important file through
--log. - The user invokes
execute_plan.py, even without the--applyoption. - The application sees that the selected path exists and calls
unlink(). - The original file is deleted.
- The logging process may recreate the path and populate it with execution-log content.
Example invocation:
bash python scripts/execute_plan.py --plan organize-plan.json --log /path/to/writable/important-fileImpact Assessment
The process can delete any existing file for which the current operating-system user has write permission. It does not provide privilege escalation beyond the privileges of the invoking process, but its scope includes user documents, application configur ...[truncated 259 chars]
- An attacker, unsafe automation, or misleading generated command supplies a writable, important file through
- Remediation
View remediation
Remediation Suggestions
- Never unconditionally delete a caller-selected log path.
- Create new logs using exclusive creation mode so an existing file causes a safe failure:
python with log_path.open("x", encoding="utf-8") as handle: ... - Generate collision-resistant log names rather than replacing existing files.
- Resolve the requested log path and require it to remain inside an explicitly approved report directory.
- If log replacement is required, introduce a separate explicit option such as
--overwrite-logand display the resolved path before deletion. - Verify that an existing path is a regular file previously created by this application before permitting replacement.
- Ensure dry-run mode performs no destructive filesystem operations. If reports are produced during dry-run, they should use new, non-conflicting output paths.
- Add automated tests confirming that existing files cannot be removed through
--log, both with and without--apply.
