Skip to content

git: Stop validating symlink target paths#2114

Merged
pjbgf merged 1 commit into
go-git:mainfrom
pjbgf:symlink
May 12, 2026
Merged

git: Stop validating symlink target paths#2114
pjbgf merged 1 commit into
go-git:mainfrom
pjbgf:symlink

Conversation

@pjbgf

@pjbgf pjbgf commented May 12, 2026

Copy link
Copy Markdown
Member

The Symlink wrapper was running validPath on both the target and the link. Targets are an opaque string the kernel resolves at use time, so legitimate worktrees commonly contain symlinks pointing to absolute paths or escaping via "..". Validating them as worktree paths rejected those checkouts. Containment is enforced on the link name, which is where the wrapper actually controls placement.

Reverts 0ae66bd, which added validation on symlink target which does not align with upstream.

Relates to #2107.

Copilot AI review requested due to automatic review settings May 12, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts worktreeFilesystem.Symlink to validate only the link name (the path being created in the worktree) and to stop applying worktree path validation rules to the symlink target, aligning behavior with upstream Git and fixing checkouts of repositories that contain symlinks with absolute or ..-escaping targets (ref: #2107).

Changes:

  • Stop running validPath on symlink targets; validate only the symlink link name.
  • Update/expand tests to assert that symlink targets are treated as opaque strings and can be arbitrary.
  • Add an end-to-end checkout test ensuring worktree checkout succeeds and remains clean with “non-worktree-contained” symlink targets.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
worktree_fs.go Changes symlink validation to check only the link path, not the target.
worktree_fs_test.go Updates symlink validation tests to reject dangerous link names but allow arbitrary targets.
worktree_test.go Adds an integration test covering checkout of symlinks with arbitrary targets.

Comment thread worktree_test.go
The Symlink wrapper was running validPath on both the target and the
link. Targets are an opaque string the kernel resolves at use time, so
legitimate worktrees commonly contain symlinks pointing to absolute
paths or escaping via "..". Validating them as worktree paths rejected
those checkouts. Containment is enforced on the link name, which is
where the wrapper actually controls placement.

Assisted-by: Claude Opus 4.7 <[email protected]>
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf pjbgf changed the title worktree: stop validating symlink target paths git: Stop validating symlink target paths May 12, 2026
@pjbgf pjbgf merged commit 67af7da into go-git:main May 12, 2026
19 checks passed
@pjbgf pjbgf deleted the symlink branch May 12, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants