Skip to content

[repo-assist] Prevent home directory deletion from malformed github/git source spec - #4389

Merged
dsyme merged 1 commit into
masterfrom
repo-assist/fix-issue-4306-home-dir-deletion-04738c977b6bfe0a
Aug 29, 2026
Merged

dsyme merged 1 commit into
masterfrom
repo-assist/fix-issue-4306-home-dir-deletion-04738c977b6bfe0a

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an automated AI assistant.

Closes #4306

Root cause

A malformed remote-source line in paket.dependencies, such as:

github myorg/repo:main ~>

(a ~> version operator with no version following it) is parsed by DependenciesFileParser such that the trailing ~> token ends up as the remote file's Name instead of a real file path.

ModuleResolver.computeFilePath then calls normalizePath on that name. normalizePath calls normalizeHomeDirectory, which expands any string starting with ~ into an absolute path rooted at the user's home directory. Because Path.Combine discards all preceding segments once a later segment is rooted, the computed destination directory for the source file silently became the user's actual home directory instead of a subfolder under paket-files.

RemoteDownload.DownloadSourceFiles then calls Utils.CleanDir on that path, which recursively deletes everything in it — i.e. the user's home directory.

Fix

computeFilePath in src/Paket.Core/Dependencies/ModuleResolver.fs now checks whether the normalized relative-name path is rooted/absolute after normalization, and raises a clear failwithf parse error instead of silently computing a destination path outside the intended paket-files tree. This turns a silent data-loss bug into an explicit, safe error for malformed dependency specs.

Trade-offs

  • This is a defensive guard at the point where paths are computed, rather than fixing the (more invasive) upstream version-parsing logic that misclassifies ~> as a file name. It's a minimal, surgical change that blocks the dangerous outcome for any malformed spec that could produce a rooted "name", not just this specific ~> case.
  • Users who previously (accidentally) got away with a malformed spec because it happened not to trigger this destructive path will now see an explicit error instead — this is the intended, safer behavior.

Test Status

  • dotnet build src/Paket.Core/Paket.Core.fsproj -c Release — succeeded (no new warnings/errors).
  • dotnet test tests/Paket.Tests/Paket.Tests.fsproj --filter "FullyQualifiedName~ParserSpecs" — 155 passed, 0 failed on net9.0. (net461 host could not run in this sandbox due to missing mono, an environment limitation unrelated to this change.)
  • Added a new regression test, should not compute a file path outside paket-files for a malformed github source spec, verifying that a github owner/repo:main ~> line parses with Name = "~>" and that calling .FilePath(...) now throws instead of resolving to a rooted path.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

… spec (#4306)

Root cause: DependenciesFileParser can parse a malformed remote source
line (e.g. `github myorg/repo:main ~>` with a missing version after
`~>`) such that the trailing token becomes the remote file's Name.
ModuleResolver.computeFilePath then calls normalizePath on that name,
which expands a leading '~' into an absolute path rooted at the
user's home directory (via normalizeHomeDirectory). Because
Path.Combine discards preceding segments once a later segment is
rooted, the computed destination directory silently became the
user's actual home directory instead of a paket-files subfolder.
RemoteDownload.DownloadSourceFiles then calls Utils.CleanDir on that
path, recursively deleting the user's home directory.

Fix: computeFilePath now rejects any resolved relative-name path that
turns out to be rooted/absolute, raising a clear parse error instead
of silently computing a destination outside the paket-files tree.

Co-authored-by: Copilot <[email protected]>
@dsyme
dsyme marked this pull request as ready for review August 29, 2026 09:35
@dsyme
dsyme merged commit 4584bab into master Aug 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paket deletes the home directory

1 participant