T09 · Insecure Skill Coding Practices
- Location
mpt_portfolio/cli.py:1007- Finding
Unvalidated Portfolio Name Allows Arbitrary Directory Deletion
- Content
View full analysis
None: """Delete a portfolio and all its data.""" portfolio_dir = get_portfolios_dir() / portfolio if not portfolio_dir.exists(): console.print(f"[red]Error:[/red] Portfolio '{portfolio}' does not exist.") sys.exit(1) if not force: confirmed = Confirm.ask( f"Delete portfolio '{portfolio}' and all its data (config, state, reports)?", default=False, ) if not confirmed: console.print("[dim]Cancelled.[/dim]") return shutil.rmtree(portfolio_dir) console.print(f"[green]Portfolio '{portfolio}' deleted.[/green]") ``` ### Technical Analysis The `--portfolio` argument is joined directly to the portfolios directory and then passed to `shutil.rmtree()`. The command does not call the existing `validate_portfolio_name()` function and does not verify that the resolved target remains inside the intended portfolios directory. Because `pathlib.Path` does not remove or reject `..` components during path construction, an input containing traversal sequences can identify a directory outside `portfolios/`. The existence check does not provide a security boundary; it only confirms that the attacker-selected target exists. The `--force` option bypasses the interactive confirmation, allowing the destructive operation to execute immediately. This is a violation of filesystem path confinement and least-privilege expectations for a portfolio management operation. ### Attack Path 1. An attacker or untrusted automation supplies a traversal value as the portfolio name. 2. ...[truncated 1107 chars]- Remediation
View remediation
