Skip to content

Commit f5cd336

Browse files
committed
fix: validate branchOverride to prevent path traversal in worktree creation
Reject absolute paths and values that escape .ralphex/worktrees/ when --branch override is used as a filesystem path element.
1 parent 636fc11 commit f5cd336

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

pkg/git/service.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,14 @@ func (s *Service) CreateWorktreeForPlan(planFile, defaultBranch, branchOverride
279279
if earlyBranch == "" {
280280
earlyBranch = plan.ExtractBranchName(planFile)
281281
}
282-
wtPath := filepath.Join(s.repo.root(), ".ralphex", "worktrees", earlyBranch)
282+
wtBase := filepath.Join(s.repo.root(), ".ralphex", "worktrees")
283+
wtPath := filepath.Join(wtBase, earlyBranch)
284+
if filepath.IsAbs(earlyBranch) {
285+
return "", false, fmt.Errorf("invalid branch name %q: must not be an absolute path", earlyBranch)
286+
}
287+
if rel, err := filepath.Rel(wtBase, wtPath); err != nil || strings.HasPrefix(rel, "..") {
288+
return "", false, fmt.Errorf("invalid branch name %q: must not escape worktrees directory", earlyBranch)
289+
}
283290

284291
// prune stale worktree entries first
285292
if pruneErr := s.repo.pruneWorktrees(); pruneErr != nil {

0 commit comments

Comments
 (0)