T09 · Insecure Skill Coding Practices
- Location
scripts/python_env_tool.py:37- Finding
Arbitrary Recursive Directory Deletion via User-Controlled Virtual Environment Path
- Content
View full analysis
Vulnerability Details
File Location:
scripts/python_env_tool.py, lines 37–40
Vulnerability Type: Unrestricted recursive deletion of a caller-controlled path
Risk Level: HighVulnerable Code:
python def cmd_bootstrap(args: argparse.Namespace) -> int: venv = Path(args.venv) if args.recreate and venv.exists(): shutil.rmtree(venv) if not venv.exists(): _run([sys.executable, "-m", "venv", str(venv)])The affected path is supplied through the unrestricted
--venvargument at lines 91–92:python bootstrap.add_argument("--venv", default=".venv", help="venv path (default: .venv)") bootstrap.add_argument("--recreate", action="store_true", help="delete and recreate venv")Technical Analysis
The
bootstrapcommand converts the caller-provided--venvvalue directly into aPath. If--recreateis present and that path exists, the program passes it toshutil.rmtree()without validating that:- The path is a virtual environment.
- The path is inside the current project.
- The resolved path is not the project root, user home, or another sensitive directory.
- The path contains a virtual-environment marker such as
pyvenv.cfg. - The user has explicitly confirmed the resolved deletion target.
This creates a destructive path-manipulation vulnerability. An accidental argument or attacker-influenced Agent instruction can select any writable directory for recursive deletion. Argument-list execution in
_run()prevents shell injection, but it does not mitigate the unsafe filesystem operation.Attack Path
-
An attacker-controlled task, prompt, automation input, or operator mistake influences the value passed to
--venv. -
The helper is invoked with both
--recreateand a path to a valuable writable directory, for example:bash scripts/python_env_tool.py bootstrap --recreate --venv /path/to/writable/data -
`Path ...[truncated 833 chars]
- Remediation
View remediation
Remediation Suggestions
- Resolve and normalize both the project root and requested virtual-environment path before any deletion.
- Require the deletion target to be a strict descendant of the project root; reject the project root itself and all paths outside it.
- Reject filesystem roots, the current user's home directory, empty paths,
.and other sensitive targets. - Before deletion, require a recognized virtual-environment marker such as
pyvenv.cfgand verify the expected interpreter layout. - Consider restricting
--recreateto a fixed project-local directory such as.venvrather than accepting arbitrary paths. - Display the resolved deletion target and require explicit confirmation for destructive operations, with a separate carefully named noninteractive override for trusted automation.
- Refuse deletion when validation is ambiguous, including unexpected symlink or path-resolution conditions.
- Add automated tests covering absolute paths, parent traversal, project-root selection, home-directory selection, filesystem roots, symlinks, and directories that are not virtual environments.
