From 4c185d5a66ec0be843cfef9e70176d902742e039 Mon Sep 17 00:00:00 2001 From: Feng Ruohang Date: Wed, 5 Aug 2026 00:57:10 +0800 Subject: [PATCH] ci: stop interpolating the dispatch tag into the release script The compute step spliced ${{ github.event.inputs.tag }} straight into the run: body, so a dispatch tag containing shell metacharacters was parsed as script - arbitrary code in a job holding a contents:write token. Pass the input through the environment instead (INPUT_TAG), the same shape docker-release.yml already uses, so the value reaches bash as data. Second vector: the old format check compared the sed output against the input to decide validity, and sed anchors ^...$ per line. A tag carrying a newline passed the check on its first line and the remaining lines flowed into $GITHUB_ENV, setting arbitrary variables (PATH, LD_PRELOAD, ...) for every later step. Replace it with a bash =~ whitelist anchored to the whole string, which rejects any multi-line value up front. Verified: a legal RELEASE.* tag is accepted and yields the right PKG_VERSION; a `"; touch ...; #` injection and a newline-carrying PATH/LD_PRELOAD payload are both rejected; an empty input falls back to the git ref name. Co-authored-by: Claude --- .github/workflows/release.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fa4f7644c..259f2dc91 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,15 +38,24 @@ jobs: fi - name: Compute release variables + env: + # Passed through the environment, never interpolated into the script + # body: a dispatch input reaches bash as data, so it cannot inject + # commands the way a `${{ ... }}` splice into the source would. + INPUT_TAG: ${{ github.event.inputs.tag }} run: | set -euo pipefail - TAG="${{ github.event.inputs.tag || github.ref_name }}" - VERSION_HYPHEN="${TAG#RELEASE.}" - PKG_VERSION="$(echo "${VERSION_HYPHEN}" | sed -E 's/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2})-([0-9]{2})-([0-9]{2})Z$/\1\2\3\4\5\6.0.0/')" - if [ "${PKG_VERSION}" = "${VERSION_HYPHEN}" ]; then - echo "Invalid release tag format: ${TAG}" + TAG="${INPUT_TAG:-${GITHUB_REF_NAME}}" + # Whitelist the exact tag shape before the value is used anywhere. bash + # =~ anchors ^...$ to the whole string (not per line, as sed would), so + # a tag carrying a newline cannot pass and then smuggle extra lines into + # $GITHUB_ENV below. + if [[ ! "${TAG}" =~ ^RELEASE\.[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}Z$ ]]; then + echo "Invalid release tag format: ${TAG}" >&2 exit 1 fi + VERSION_HYPHEN="${TAG#RELEASE.}" + PKG_VERSION="$(echo "${VERSION_HYPHEN}" | sed -E 's/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2})-([0-9]{2})-([0-9]{2})Z$/\1\2\3\4\5\6.0.0/')" VERSION_COLON="$(echo "${VERSION_HYPHEN}" | sed -E 's/T([0-9]{2})-([0-9]{2})-([0-9]{2})Z$/T\1:\2:\3Z/')" LDFLAGS="$(MINIO_RELEASE=RELEASE go run buildscripts/gen-ldflags.go "${VERSION_COLON}")"