From 02eb4e7297f60d575ebd97aba4c4fa199d4a0459 Mon Sep 17 00:00:00 2001 From: Niels Kootstra <545768+nkootstra@users.noreply.github.com> Date: Thu, 1 Oct 2026 04:44:42 +0200 Subject: [PATCH] build: verify Maven distribution checksums (#4751) * build: verify Maven distribution checksums Pin distributionSha256Sum in the Maven wrapper so mvnw rejects a tampered download, and check Apache's published SHA-512 before extracting Maven in Dockerfile.native. * build: require unzip when the Maven wrapper checksum is pinned Without unzip, mvnw downloads the .tar.gz distribution and checks it against the .zip checksum, reporting a possibly compromised download. Stop with a clear message instead. --- .mvn/wrapper/maven-wrapper.properties | 1 + docker/Dockerfile.native | 6 +++++- mvnw | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 216df05897..a3c407ffc2 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,3 +1,4 @@ wrapperVersion=3.3.4 distributionType=only-script distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip +distributionSha256Sum=5af3b743dd8b876b5c45da33b676251e5f1687712644abb4ee519ca56e1d89ce diff --git a/docker/Dockerfile.native b/docker/Dockerfile.native index 3f7d257b68..db3f3d5fe2 100644 --- a/docker/Dockerfile.native +++ b/docker/Dockerfile.native @@ -4,7 +4,11 @@ USER root WORKDIR /app # Install Maven 3.9.x (system Maven is too old for Quarkus 3.31) -RUN curl -fsSL https://archive.apache.org/dist/maven/maven-3/3.9.12/binaries/apache-maven-3.9.12-bin.tar.gz | tar xz -C /opt \ +# The SHA-512 is Apache's published checksum for apache-maven-3.9.12-bin.tar.gz. +RUN curl -fsSL -o /tmp/maven.tar.gz https://archive.apache.org/dist/maven/maven-3/3.9.12/binaries/apache-maven-3.9.12-bin.tar.gz \ + && echo "0a1be79f02466533fc1a80abbef8796e4f737c46c6574ede5658b110899942a94db634477dfd3745501c80aef9aac0d4f841d38574373f7e2d24cce89d694f70 /tmp/maven.tar.gz" | sha512sum -c - \ + && tar xzf /tmp/maven.tar.gz -C /opt \ + && rm /tmp/maven.tar.gz \ && ln -sf /opt/apache-maven-3.9.12/bin/mvn /usr/local/bin/mvn COPY pom.xml . diff --git a/mvnw b/mvnw index bd8896bf22..7b2fade6fb 100755 --- a/mvnw +++ b/mvnw @@ -177,6 +177,8 @@ verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" # select .zip or .tar.gz if ! command -v unzip >/dev/null; then + # distributionSha256Sum is the checksum of the .zip, so the .tar.gz fallback cannot be verified + [ -z "${distributionSha256Sum-}" ] || die "unzip is required to install Maven because distributionSha256Sum is set in maven-wrapper.properties. Please install unzip." distributionUrl="${distributionUrl%.zip}.tar.gz" distributionUrlName="${distributionUrl##*/}" fi