Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Paket.Core/Dependencies/ModuleResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type Origin =

let internal computeFilePath(owner,project,root,groupName:GroupName,name : string) =
let path = normalizePath (name.TrimStart('/'))
// A malformed dependency spec (e.g. a missing version after "~>") can cause the
// "file name" part to be parsed as "~>", which normalizePath then expands into an
// absolute path rooted at the user's home directory. Path.Combine silently discards
// the preceding (root-relative) segments whenever a later segment is rooted, which
// would otherwise make the computed destination point outside of the intended
// paket-files directory - see https://github.com/fsprojects/Paket/issues/4306
if Path.IsPathRooted path then
failwithf "Invalid remote file specification '%s' for %s/%s - the resolved file name must not be an absolute path" name owner project
let owner = if String.IsNullOrWhiteSpace owner then "localhost" else owner
let dir =
if groupName = Constants.MainDependencyGroup then
Expand Down
15 changes: 15 additions & 0 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,21 @@ let ``should read github source file from config without quotes``() =
PackagePath = None
AuthKey = Some "github" }]

[<Test>]
let ``should not compute a file path outside paket-files for a malformed github source spec``() =
// Regression test for https://github.com/fsprojects/Paket/issues/4306 :
// "github myorg/repo:main ~>" (a missing version after "~>") used to be parsed
// such that the "~>" ended up as the remote file's Name, which normalizePath then
// expanded into an absolute path rooted at the user's home directory. This made
// Path.Combine discard the paket-files root entirely, so a subsequent CleanDir
// wiped out the user's home directory instead of a paket-files subfolder.
let config = """github myorg/repo:main ~>"""
let dependencies = DependenciesFile.FromSource(config)
let remoteFile = dependencies.Groups.[Constants.MainDependencyGroup].RemoteFiles.Head
remoteFile.Name |> shouldEqual "~>"
(fun () -> remoteFile.FilePath("/some/root", Constants.MainDependencyGroup) |> ignore)
|> shouldFail

[<Test>]
let ``should read github source file from config with quotes``() =
let config = """github fsharp/FAKE:master "src/app/FAKE/Cli.fs"
Expand Down
Loading