-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
348: Mitigate dependency confusion r=GunnarFarneback a=GunnarFarneback This PR adds a dependency confusion mitigation mechanism for public registries beside General, which are particularly exposed to the vulnerability since their UUIDs are, well, public. The idea, once this PR goes live, is that public registries who want to take part of this mitigation would submit a PR against https://github.com/JuliaRegistries/General/blob/master/.github/workflows/automerge.yml to add their repo URL to the `RegistryCI.AutoMerge.run` argument `public_registries`. When automerge runs, it will clone those repositories and check for a UUID conflict when examining a new-package request. If a conflict is found automerge is blocked, usually. There is one exception to this rule. Assume you want to add a package to General that has previously lived in one of the checked public repositories. Obviously this will trigger a UUID conflict. However, in this case the package repository will match, which means that 1. An attacker has no way to add rouge versions. 2. Registrator wouldn't have accepted the registration request from someone unauthorized. So the rule is that automerge is blocked for conflicting UUIDs, unless repository URL and package name match. (Same UUID with different names is no good, regardless of dependency confusion.) There are some outstanding questions of how much time this takes and whether it gracefully handles connection problems for the public registries. Cc: @timholy Co-authored-by: Gunnar Farnebäck <gunnar.farneback@contextvision.se>
- Loading branch information
Showing
29 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# TODO: Add a more thorough explanation of the dependency confusion | ||
# vulnerability and how this guideline mitigates it. | ||
|
||
const guideline_dependency_confusion = | ||
Guideline("No UUID conflict with other registries.", | ||
data -> has_no_dependency_confusion(data.pkg, | ||
data.registry_head, | ||
data.public_registries)) | ||
|
||
# TODO: Needs a strategy to handle connection failures for the public | ||
# registries. Preferably they should also be cloned only once and then | ||
# just updated to mitigate the effect of them being temporarily | ||
# offline. This could be implemented with the help of the Scratch | ||
# package, but requires Julia >= 1.5. | ||
function has_no_dependency_confusion(pkg, registry_head, public_registries) | ||
# We know the name of this package but not its uuid. Look it up in | ||
# the registry that includes the current PR. | ||
packages = TOML.parsefile(joinpath(registry_head, "Registry.toml"))["packages"] | ||
filter!(packages) do (key, value) | ||
value["name"] == pkg | ||
end | ||
# For Julia >= 1.4 this can be simplified with the `only` function. | ||
always_assert(length(packages) == 1) | ||
uuid = first(keys(packages)) | ||
# Also need to find out the package repository. | ||
package_repo = TOML.parsefile(joinpath(registry_head, packages[uuid]["path"], "Package.toml"))["repo"] | ||
for repo in public_registries | ||
try | ||
registry = clone_repo(repo) | ||
registry_toml = TOML.parsefile(joinpath(registry, "Registry.toml")) | ||
packages = registry_toml["packages"] | ||
if haskey(packages, uuid) | ||
message = string("UUID $uuid conflicts with the package ", | ||
packages[uuid]["name"], " in registry ", | ||
registry_toml["name"], " at $repo.\n", | ||
"This could be a dependency confusion attack.") | ||
# Conflict detected. This is benign if the package name | ||
# *and* the package URL matches. | ||
if packages[uuid]["name"] != pkg | ||
return false, message | ||
end | ||
package_path = packages[uuid]["path"] | ||
other_package_repo = TOML.parsefile(joinpath(registry, package_path, "Package.toml"))["repo"] | ||
if package_repo != other_package_repo | ||
return false, message | ||
end | ||
end | ||
catch | ||
message = string("Failed to clone public registry $(repo) for a check against dependency confusion.\n", | ||
"This is an internal issue with the AutoMerge process and has nothing to do with ". | ||
"the package being registered but requires manual intervention before AutoMerge ", | ||
"can be resumed.") | ||
return false, message | ||
end | ||
end | ||
|
||
return true, "" | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
["0.5.3-0"] | ||
julia = "1" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = "Example" | ||
uuid = "7876af07-990d-54b4-ab0e-23690620f79a" | ||
repo = "https://github.com/JuliaLang/Example.jl.git" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
["0.5.3"] | ||
git-tree-sha1 = "46e44e869b4d90b96bd8ed1fdcf32244fddfb6cc" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name = "PublicRegistry" | ||
uuid = "1003c4b9-3c72-409d-ba60-5578a18ea1a7" | ||
repo = "" | ||
|
||
description = "This is a test registry for the AutoMerge integration tests." | ||
|
||
[packages] | ||
7876af07-990d-54b4-ab0e-23690620f79a = { name = "Example", path = "E/Example" } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[1-2] | ||
julia = "1" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = "Req" | ||
uuid = "ae029012-a4dd-5104-9daa-d747884805df" | ||
repo = "https://github.com/MikeInnes/Requires.jl.git" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
["1.0.0"] | ||
git-tree-sha1 = "999513b7dea8ac17359ed50ae8ea089e4464e35e" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name = "PublicRegistry" | ||
uuid = "1003c4b9-3c72-409d-ba60-5578a18ea1a7" | ||
repo = "" | ||
|
||
description = "This is a test registry for the AutoMerge integration tests." | ||
|
||
[packages] | ||
ae029012-a4dd-5104-9daa-d747884805df = { name = "Req", path = "R/Req" } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[1-2] | ||
julia = "1" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = "Requires" | ||
uuid = "ae029012-a4dd-5104-9daa-d747884805df" | ||
repo = "https://github.com/JuliaLang/Example.jl.git" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
["1.0.0"] | ||
git-tree-sha1 = "999513b7dea8ac17359ed50ae8ea089e4464e35e" | ||
|
||
["2.0.0"] | ||
git-tree-sha1 = "999513b7dea8ac17359ed50ae8ea089e4464e35e" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name = "PublicRegistry" | ||
uuid = "1003c4b9-3c72-409d-ba60-5578a18ea1a7" | ||
repo = "" | ||
|
||
description = "This is a test registry for the AutoMerge integration tests." | ||
|
||
[packages] | ||
ae029012-a4dd-5104-9daa-d747884805df = { name = "Requires", path = "R/Requires" } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[0-1] | ||
julia = "1" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = "Requires" | ||
uuid = "ae029012-a4dd-5104-9daa-d747884805df" | ||
repo = "https://github.com/MikeInnes/Requires.jl.git" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
["0.5.2"] | ||
git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name = "PublicRegistry" | ||
uuid = "1003c4b9-3c72-409d-ba60-5578a18ea1a7" | ||
repo = "" | ||
|
||
description = "This is a test registry for the AutoMerge integration tests." | ||
|
||
[packages] | ||
ae029012-a4dd-5104-9daa-d747884805df = { name = "Requires", path = "R/Requires" } |
97ba104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
97ba104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/30164
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: