Skip to content

fix: reject org-level URLs in RepoPathFromURL to prevent mirror deletion#219

Closed
jrobotham-square wants to merge 1 commit intomainfrom
jrobotham/reject-org-level-urls
Closed

fix: reject org-level URLs in RepoPathFromURL to prevent mirror deletion#219
jrobotham-square wants to merge 1 commit intomainfrom
jrobotham/reject-org-level-urls

Conversation

@jrobotham-square
Copy link
Copy Markdown
Contributor

Problem

A curl request to /git/github.com/squareup/ (an org-level URL with no repo) caused RepoPathFromURL to resolve the mirror path to state/git-mirrors/github.com/squareup — the parent directory containing all squareup repo mirrors.

When the clone attempt failed, startClone called os.RemoveAll(repo.Path()), wiping every squareup mirror on the pod. Subsequent requests for repos like blox, hermit-packages, and mesh all failed because the in-memory state was still StateReady but the files on disk were gone.

This caused workstation 28440 in staging to enter a degraded state when its git clone of blox hit the affected cachew pod.

Fix

RepoPathFromURL now validates that the URL contains at least an owner and repository path component (e.g. host/owner/repo). Org-only URLs like https://github.com/squareup/ are rejected with an error before any clone or directory operations occur.

Reproduction

Reproduced against a playpen — confirmed the bogus URL deletes the mirror directory with old code, and is rejected cleanly with the fix.

RepoPathFromURL now validates that the URL contains at least an owner
and repository component (e.g. host/owner/repo). Previously, an
org-only URL like https://github.com/squareup/ would resolve to the
mirror path state/git-mirrors/github.com/squareup, and a failed clone
attempt would call os.RemoveAll on that path — deleting every
squareup mirror on the pod.

This was triggered in production when a curl request to
/git/github.com/squareup/ caused startClone to wipe the parent
directory containing all squareup repo mirrors.

Amp-Thread-ID: https://ampcode.com/threads/T-019d1ca3-be59-7241-9166-3342769c959a
Co-authored-by: Amp <amp@ampcode.com>
@jrobotham-square jrobotham-square requested a review from a team as a code owner March 23, 2026 22:24
@jrobotham-square jrobotham-square requested review from js-murph and removed request for a team March 23, 2026 22:24
@alecthomas
Copy link
Copy Markdown
Collaborator

This is not the correct fix.

@alecthomas alecthomas closed this Mar 24, 2026
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