#367·plandex

apply/rewind write model-controlled paths outside the project root while the confirmation prompt only shows a file count

Author: TardfyouCreated Sep 23, 2026Updated Sep 23, 2026

Summary

During apply, file paths come from model-generated plan results and are joined onto the project root with filepath.Join, which cleans .. segments — allowing writes/deletions outside the project root. The user confirmation prompt only shows the number of files ("Apply changes to N files?"), never paths or diffs, so the escape is invisible at the consent point.

Code path (main @ e2d7720)

  • app/cli/lib/apply.go:638 / :703 — dstPath := filepath.Join(fs.ProjectRoot, path) for writes and deletes; path originates from model results (app/server/db/result_helpers.go:544+, app/shared/plan_result_replacements.go:139-272 — no path validation anywhere in the chain).
  • app/cli/lib/apply.go:181 — the only consent: ConfirmYesNo("Apply changes to %d file%s?", numToApply, …).
  • Same pattern in rewind: app/cli/lib/rewind.go:175,271.
  • Note plandex apply (explicit command) permanently sets AutoConfirm: true (app/cli/cmd/apply.go:50), so even the count prompt is skipped there.

Scenario

A repository (or loaded URL context) containing prompt-injected instructions makes the model emit a file path like ../../.bashrc (or an absolute path). The user approves "Apply changes to 3 files?" and a file outside the project root is written (or, via toRemove, deleted).

Impact

The consent gate validates a count, not the effect: model-controlled path traversal turns an approved "N-file apply" into arbitrary-path file write/delete on the user's machine.

Suggested fix

Validate every result path with a containment check (resolved path must stay under ProjectRoot) before apply/rewind; show actual paths (and out-of-root warnings) in the confirmation prompt.

Notes

Verified statically against main @ e2d7720 (2025-10-03, latest).


Reported by Chengzhi Yi (GitHub @Tardfyou) — [email protected]. Offline analysis of the public repository; no system was accessed.