Skip to content

Commit ccfc219

Browse files
authored
[Sources] Ban GitHub-generated archives as sources (#293)
1 parent ae213c6 commit ccfc219

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/Sources.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ Concrete subtypes of `AbstractSource` are:
1717
"""
1818
abstract type AbstractSource end
1919

20+
function check_github_archive(url::String)
21+
# See
22+
# * https://github.blog/changelog/2023-01-30-git-archive-checksums-may-change/
23+
# * https://github.com/bazel-contrib/SIG-rules-authors/issues/11
24+
# * https://github.com/spack/spack/issues/35250
25+
# Note: according to
26+
# <https://github.com/bazel-contrib/SIG-rules-authors/issues/11#issuecomment-1029861300>
27+
# the `/archive/refs/tag` should be more stable, but that didn't happen in the incident
28+
# on 2023-01-30, so it's unclear whether we can trust them.
29+
if contains(url, r"github.com/[^/]+/[^/]+/archive/(refs/tag/)?[^/]+\.(tar\.gz|zip)$")
30+
throw(ArgumentError("""
31+
The archive automatically generated by GitHub
32+
$(url)
33+
may not have a stable checksum in the future, thus cannot be used as a reliable source, see
34+
<https://github.blog/changelog/2023-01-30-git-archive-checksums-may-change/>.
35+
Use a different source, for example a `GitSource`, or an official release artifact uploaded
36+
by the maintainers of the package (*not* the automatic archive produced by GitHub).
37+
"""))
38+
end
39+
end
40+
2041
"""
2142
ArchiveSource(url::String, hash::String; unpack_target::String = "")
2243
@@ -32,6 +53,10 @@ struct ArchiveSource <: AbstractSource
3253
url::String
3354
hash::String
3455
unpack_target::String
56+
function ArchiveSource(url::String, hash::String, unpack_target::String)
57+
check_github_archive(url)
58+
return new(url, hash, unpack_target)
59+
end
3560
end
3661
ArchiveSource(url::String, hash::String; unpack_target::String = "") =
3762
ArchiveSource(url, hash, unpack_target)
@@ -56,6 +81,10 @@ struct FileSource <: AbstractSource
5681
url::String
5782
hash::String
5883
filename::String
84+
function FileSource(url::String, hash::String, filename::String)
85+
check_github_archive(url)
86+
return new(url, hash, filename)
87+
end
5988
end
6089
FileSource(url::String, hash::String; filename::String = basename(url)) =
6190
FileSource(url, hash, filename)

test/sources.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ using JSON
1010
@test GitSource("https://github.com/jedisct1/libsodium.git", "5b2ea7d73d3ffef2fb93b82b9f112f009d54c6e6"; unpack_target = "libs").unpack_target == "libs"
1111
@test FileSource("https://curl.haxx.se/ca/cacert-2020-01-01.pem", "adf770dfd574a0d6026bfaa270cb6879b063957177a991d453ff1d302c02081f").filename == "cacert-2020-01-01.pem"
1212
@test FileSource("https://curl.haxx.se/ca/cacert-2020-01-01.pem", "adf770dfd574a0d6026bfaa270cb6879b063957177a991d453ff1d302c02081f"; filename="cacert.pem").filename == "cacert.pem"
13+
# GitHub-generated archives are banned
14+
@test_throws ArgumentError ArchiveSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff")
15+
@test_throws ArgumentError ArchiveSource("https://github.com/ralna/ARCHDefs/archive/refs/tag/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff")
16+
@test_throws ArgumentError FileSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff")
17+
@test_throws ArgumentError FileSource("https://github.com/ralna/ARCHDefs/archive/refs/tag/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff")
1318

1419
@test SetupSource("https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz", "wget-1.20.3.tar.gz", "", "") isa SetupSource{ArchiveSource}
1520
@test SetupSource("https://ftp.gnu.org/gnu/wget/wget-1.20.3.zip", "wget-1.20.3.zip", "", "") isa SetupSource{ArchiveSource}
@@ -20,12 +25,12 @@ using JSON
2025
@testset "Download and setup" begin
2126
mktempdir() do dir
2227
cd(dir) do
23-
as = ArchiveSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff")
28+
as = ArchiveSource("https://github.com/JuliaBinaryWrappers/libcellml_jll.jl/releases/download/libcellml-v0.4.0%2B0/libcellml-logs.v0.4.0.x86_64-w64-mingw32-cxx03.tar.gz", "237013b20851355c4c1d22ceac7e73207b44d989d38b6874187d333adfc79c77")
2429
# Download the source
2530
sas = @test_logs (:info, r"Downloading .* to.*") download_source(as; verbose = true, downloads_dir = dir)
2631
# Check that the cache is found
2732
@test @test_logs (:info, r"Cached file found in .*") download_source(as; verbose = true, downloads_dir = dir) == sas
28-
fs = FileSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff"; filename = "file-source.tar.gz")
33+
fs = FileSource("https://github.com/JuliaBinaryWrappers/libcellml_jll.jl/releases/download/libcellml-v0.4.0%2B0/libcellml-logs.v0.4.0.x86_64-w64-mingw32-cxx03.tar.gz", "237013b20851355c4c1d22ceac7e73207b44d989d38b6874187d333adfc79c77"; filename = "file-source.tar.gz")
2934
# Re-fetch the same tarball, as a `FileSource` this time
3035
sfs = @test_logs (:info, r"Cached file found in .*") download_source(fs; verbose = true, downloads_dir = dir)
3136
gs = GitSource("https://github.com/ralna/ARCHDefs.git", "fc8c5960c3a6d26970ab245241cfc067fe4ecfdd")
@@ -90,7 +95,7 @@ using JSON
9095
@test islink(joinpath(target, "link.patch"))
9196

9297
# Make sure in srcdir there are all files and directories we expect
93-
@test Set(readdir(srcdir)) == Set(["ARCHDefs", "ARCHDefs-2.0.3x", fs.filename, "patches_follow", "patches_nofollow"])
98+
@test Set(readdir(srcdir)) == Set(["ARCHDefs", "logs", fs.filename, "patches_follow", "patches_nofollow"])
9499

95100
# Setup the sources with `setup_workspace`
96101
workspace = joinpath(dir, "workspace")

0 commit comments

Comments
 (0)