Skip to content

Commit a85e912

Browse files
authored
fix: verify generator jar sha256 before executing it (#2)
1 parent 0f86b87 commit a85e912

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎scripts/generate.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ SPEC_URL="${SPEC_URL:-https://raw.githubusercontent.com/frain-dev/convoy/main/do
1111
# Pin so regeneration output is reproducible; bump deliberately.
1212
GENERATOR_VERSION="7.23.0"
1313
GENERATOR_JAR="${GENERATOR_JAR:-.cache/openapi-generator-cli-${GENERATOR_VERSION}.jar}"
14+
# Official artifact checksum; the download is verified before execution so a
15+
# compromised mirror/CDN cannot run arbitrary code in CI. Update alongside
16+
# GENERATOR_VERSION (sha256 of the Maven Central JAR).
17+
GENERATOR_SHA256="cb087e40001e31eb08ef6140dd5de10938dbeb89016a1fe0481eaa25cd569026"
1418

1519
tmp="$(mktemp -d)"
1620
trap 'rm -rf "$tmp"' EXIT
@@ -21,6 +25,12 @@ if [ ! -f "$GENERATOR_JAR" ]; then
2125
"https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${GENERATOR_VERSION}/openapi-generator-cli-${GENERATOR_VERSION}.jar"
2226
fi
2327

28+
# Fail closed on checksum mismatch (covers cached files too).
29+
echo "${GENERATOR_SHA256} ${GENERATOR_JAR}" | shasum -a 256 -c - >/dev/null || {
30+
echo "ERROR: ${GENERATOR_JAR} failed sha256 verification" >&2
31+
exit 1
32+
}
33+
2434
curl -fsSL "$SPEC_URL" -o "$tmp/openapi3.yaml"
2535

2636
# hideGenerationTimestamp: @Generated annotations must not embed a wall-clock

0 commit comments

Comments
 (0)