Skip to content

plumbing: transport, resolve ..-relative file URLs against CWD#1891

Open
AriehSchneier wants to merge 1 commit intogo-git:mainfrom
AriehSchneier:fix-relative-clone-url
Open

plumbing: transport, resolve ..-relative file URLs against CWD#1891
AriehSchneier wants to merge 1 commit intogo-git:mainfrom
AriehSchneier:fix-relative-clone-url

Conversation

@AriehSchneier
Copy link
Copy Markdown
Contributor

When a caller passes a URL like "../../some-repo" to Clone, parseFile produced an Endpoint{Path:"../../..."} that was handed unchanged to the chroot-based FilesystemLoader. The billy ChrootHelper rejects any path whose cleaned form starts with ".." ("chroot boundary crossed"), regardless of the chroot root.

Fix: in parseFile, detect paths whose cleaned form starts with ".." and resolve them to absolute paths via filepath.Abs before storing them in the Endpoint. This matches the behaviour of git clone: relative paths are resolved against the caller's working directory.

Adds TestClone_RelativeURL as a regression test.

Fixes: #1723

@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from 18368d6 to f410dd2 Compare March 10, 2026 22:38
@AriehSchneier AriehSchneier marked this pull request as draft March 11, 2026 22:40
@AriehSchneier AriehSchneier marked this pull request as ready for review March 11, 2026 22:40
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 2 times, most recently from 0501e13 to a17004f Compare March 16, 2026 23:23
@AriehSchneier AriehSchneier requested a review from pjbgf March 16, 2026 23:33
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 8 times, most recently from 496c425 to a4e8d7e Compare March 23, 2026 23:00
Comment on lines +185 to +186
if !filepath.IsAbs(path) &&
(cleaned == ".." || strings.HasPrefix(cleaned, ".."+string(filepath.Separator))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AriehSchneier I'm under the impression this needs to be handled higher up the stack e.g. Clone/Open.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have moved it to CloneOptions.Validate() which fixes it in the Clone case (which is where I was hitting the error), but what if someone calls transport.NewEndpoint() directly it will no longer resolve.

@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 7 times, most recently from 719bc65 to ad59a5b Compare March 31, 2026 00:43
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from cee6d69 to 13fd8bc Compare April 4, 2026 13:22
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from 6439da7 to b9ea6e8 Compare April 14, 2026 10:50
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch from b9ea6e8 to 59bbe1b Compare April 14, 2026 14:51
…ptions.Validate

When a caller passes a URL like "../../some-repo" to Clone, the billy chroot-based FilesystemLoader rejects any path whose cleaned form starts with ".." with "chroot boundary crossed".

Fix: in CloneOptions.Validate, detect local-endpoint paths whose clean form starts with ".." and resolve them to absolute paths via filepath.Abs before any transport code runs. This matches the behaviour of `git clone`: relative paths are resolved against the caller's working directory at the command level, before handing the URL to the transport layer.

Fixes: go-git#1723

Assisted-by: GitHub Copilot (claude-sonnet-4-6) <copilot@github.com>
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch from 59bbe1b to 222e215 Compare April 14, 2026 22: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.

v6: Clone of parent fails (worked in v5)

2 participants