fix: reject org-level URLs in RepoPathFromURL to prevent mirror deletion#219
Closed
jrobotham-square wants to merge 1 commit intomainfrom
Closed
fix: reject org-level URLs in RepoPathFromURL to prevent mirror deletion#219jrobotham-square wants to merge 1 commit intomainfrom
jrobotham-square wants to merge 1 commit intomainfrom
Conversation
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>
stuartwdouglas
approved these changes
Mar 23, 2026
Collaborator
|
This is not the correct fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A
curlrequest to/git/github.com/squareup/(an org-level URL with no repo) causedRepoPathFromURLto resolve the mirror path tostate/git-mirrors/github.com/squareup— the parent directory containing all squareup repo mirrors.When the clone attempt failed,
startClonecalledos.RemoveAll(repo.Path()), wiping every squareup mirror on the pod. Subsequent requests for repos likeblox,hermit-packages, andmeshall failed because the in-memory state was stillStateReadybut the files on disk were gone.This caused workstation 28440 in staging to enter a degraded state when its git clone of
bloxhit the affected cachew pod.Fix
RepoPathFromURLnow validates that the URL contains at least an owner and repository path component (e.g.host/owner/repo). Org-only URLs likehttps://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.