You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Clone abort can recursively delete an unowned destination path #2929
Clone abort can recursively delete an unowned destination path
Category: data-loss · Severity: high · Confidence: high · Affects: macOS, Linux, Windows
Impact
Aborting a clone can recursively delete a pre-existing, user-owned destination directory that the clone never created.
Location
src/main/ipc/repos.ts:624-635 (line numbers as of main at filing)
Reproduction
In a unit test, make gitSpawn return an EventEmitter that does not emit close. Register repo handlers, call handlers.get('repos:clone') without awaiting it using { url: 'file:///tmp/source/.', destination: '/Users/alice/projects' }, then call handlers.get('repos:cloneAbort'). activeClonePath is set to join('/Users/alice/projects', '.') and cloneAbort calls rm('/Users/alice/projects', { recursive: true, force: true }).
Suggested fix
Validate the derived clone directory name and reject '.', '..', empty names, and any path segment that normalizes outside args.destination. Before spawning git, record whether clonePath already exists and only cleanup a path that this clone created. Prefer creating a unique temporary clone directory and renaming after success, or use an ownership marker so abort cleanup cannot target user-owned paths.
Minimum fix scope: src/main/ipc/repos.ts clone name validation plus clone cleanup ownership tracking; add focused tests in src/main/ipc/repos-remote.test.ts or a repos-clone-abort test file.
Why existing tests miss it
The included repos clone tests cover successful clone creation and folder-to-git dedupe, but there is no cloneAbort test and no coverage for dot-segment URLs or cleanup ownership.
Suggested regression test
Add a repos:cloneAbort test with a pending mocked gitSpawn and url 'file:///tmp/source/.'; assert rm is not called on the destination parent and the handler rejects the URL before setting activeClonePath. Add a second test where clonePath already exists before spawn and abort does not remove it.
Activity