Skip to content

Commit 32d20fd

Browse files
maennchenjosevalim
authored andcommitted
Prevent template injection in GitHub Actions workflows
Use environment variables instead of direct template expansion in shell run blocks to prevent potential code injection. See: https://docs.zizmor.sh/audits/#template-injection
1 parent dfe857e commit 32d20fd

3 files changed

Lines changed: 37 additions & 30 deletions

File tree

.github/workflows/release.yml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ jobs:
3737
if: github.ref_type != 'branch'
3838
run: |
3939
gh release create \
40-
--repo ${{ github.repository }} \
41-
--title ${{ github.ref_name }} \
40+
--repo "$GITHUB_REPOSITORY" \
41+
--title "$GITHUB_REF_NAME" \
4242
--notes '' \
4343
--draft \
44-
${{ github.ref_name }}
44+
"$GITHUB_REF_NAME"
4545
4646
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4747
if: github.ref_type == 'branch'
@@ -51,18 +51,18 @@ jobs:
5151
- name: Update ${{ github.ref_name }}-latest
5252
if: github.ref_type == 'branch'
5353
run: |
54-
ref_name=${{ github.ref_name }}-latest
54+
ref_name="${GITHUB_REF_NAME}-latest"
5555
56-
if ! gh release view $ref_name; then
56+
if ! gh release view "$ref_name"; then
5757
gh release create \
5858
--latest=false \
59-
--title $ref_name \
60-
--notes "Automated release for latest ${{ github.ref_name }}." \
61-
$ref_name
59+
--title "$ref_name" \
60+
--notes "Automated release for latest ${GITHUB_REF_NAME}." \
61+
"$ref_name"
6262
fi
6363
64-
git tag $ref_name --force
65-
git push origin $ref_name --force
64+
git tag "$ref_name" --force
65+
git push origin "$ref_name" --force
6666
6767
build:
6868
name: Ubuntu 24.04, OTP ${{ matrix.otp_version }}${{ matrix.build_docs && ' (build docs)' || '' }}
@@ -247,12 +247,16 @@ jobs:
247247
cp "$ATTESTATION" "attestations/$(basename "$FILE").sigstore"
248248
done
249249
250-
cp "$ATTESTATION" "attestations/$(basename "${{ steps.ort.outputs.results-sbom-cyclonedx-xml-path }}").sigstore"
251-
cp "$ATTESTATION" "attestations/$(basename "${{ steps.ort.outputs.results-sbom-cyclonedx-json-path }}").sigstore"
252-
cp "$ATTESTATION" "attestations/$(basename "${{ steps.ort.outputs.results-sbom-spdx-yml-path }}").sigstore"
253-
cp "$ATTESTATION" "attestations/$(basename "${{ steps.ort.outputs.results-sbom-spdx-json-path }}").sigstore"
250+
cp "$ATTESTATION" "attestations/$(basename "$SBOM_CYCLONEDX_XML").sigstore"
251+
cp "$ATTESTATION" "attestations/$(basename "$SBOM_CYCLONEDX_JSON").sigstore"
252+
cp "$ATTESTATION" "attestations/$(basename "$SBOM_SPDX_YML").sigstore"
253+
cp "$ATTESTATION" "attestations/$(basename "$SBOM_SPDX_JSON").sigstore"
254254
env:
255255
ATTESTATION: "${{ steps.attest-sbom.outputs.bundle-path }}"
256+
SBOM_CYCLONEDX_XML: "${{ steps.ort.outputs.results-sbom-cyclonedx-xml-path }}"
257+
SBOM_CYCLONEDX_JSON: "${{ steps.ort.outputs.results-sbom-cyclonedx-json-path }}"
258+
SBOM_SPDX_YML: "${{ steps.ort.outputs.results-sbom-spdx-yml-path }}"
259+
SBOM_SPDX_JSON: "${{ steps.ort.outputs.results-sbom-spdx-json-path }}"
256260

257261
- name: "Assemble Release SBoM Artifacts"
258262
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
@@ -289,14 +293,14 @@ jobs:
289293
env:
290294
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
291295
run: |
292-
if [ "${{ github.ref_type }}" == "branch" ]; then
293-
tag=${{ github.ref_name }}-latest
296+
if [ "$GITHUB_REF_TYPE" == "branch" ]; then
297+
tag="${GITHUB_REF_NAME}-latest"
294298
else
295-
tag="${{ github.ref_name }}"
299+
tag="$GITHUB_REF_NAME"
296300
fi
297301
298302
gh release upload \
299-
--repo ${{ github.repository }} \
303+
--repo "$GITHUB_REPOSITORY" \
300304
--clobber \
301305
"$tag" \
302306
elixir-otp-*.zip \
@@ -341,12 +345,10 @@ jobs:
341345
342346
- name: Upload Precompiled to S3
343347
run: |
344-
ref_name=${{ github.ref_name }}
345-
346348
oldest_otp=$(find . -type f -name 'elixir-otp-*.zip' | sed -r 's/^.*elixir-otp-([[:digit:]]+)\.zip$/\1/' | sort -n | head -n 1)
347349
348350
for zip in $(find . -type f -name 'elixir-otp-*.zip' | sed 's/^\.\///'); do
349-
dest=${zip/elixir/${ref_name}}
351+
dest=${zip/elixir/${GITHUB_REF_NAME}}
350352
surrogate_key=${dest/.zip$/}
351353
352354
aws s3 cp "${zip}" "s3://${AWS_S3_BUCKET}/builds/elixir/${dest}" \
@@ -358,13 +360,13 @@ jobs:
358360
aws s3 cp "${zip}" "s3://${AWS_S3_BUCKET}/builds/elixir/${ref_name}.zip" \
359361
--cache-control "public,max-age=3600" \
360362
--metadata "{\"surrogate-key\":\"builds builds/elixir builds/elixir/${ref_name}\",\"surrogate-control\":\"public,max-age=604800\"}"
361-
echo builds/elixir/${ref_name} >> purge_keys.txt
363+
echo builds/elixir/${GITHUB_REF_NAME} >> purge_keys.txt
362364
fi
363365
done
364366
365367
- name: Upload Docs to S3
366368
run: |
367-
version=$(echo ${{ github.ref_name }} | sed -e 's/^v//g')
369+
version=$(echo "$GITHUB_REF_NAME" | sed -e 's/^v//g')
368370
369371
unzip Docs.zip
370372
@@ -385,7 +387,7 @@ jobs:
385387
- name: Update builds txt
386388
run: |
387389
date="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
388-
ref_name=${{ github.ref_name }}
390+
ref_name="$GITHUB_REF_NAME"
389391
390392
oldest_otp=$(find . -name 'elixir-otp-*.zip.sha256sum' | sed -r 's/^.*elixir-otp-([[:digit:]]+)\.zip\.sha256sum$/\1/' | sort -n | head -n 1)
391393

.github/workflows/release_notifications.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
ELIXIR_FORUM_TOKEN: ${{ secrets.ELIXIR_FORUM_TOKEN }}
3232
ELIXIR_LANG_ANN_TOKEN: ${{ secrets.ELIXIR_LANG_ANN_TOKEN }}
3333
run: |
34-
elixir .github/workflows/notify.exs ${{ github.ref_name }}
34+
elixir .github/workflows/notify.exs "$GITHUB_REF_NAME"

.github/workflows/release_pre_built/action.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ runs:
2727
shell: bash
2828
run: |
2929
make Precompiled.zip
30-
mv Precompiled.zip elixir-otp-${{ inputs.otp }}.zip
30+
mv Precompiled.zip "elixir-otp-${INPUT_OTP}.zip"
3131
echo "$PWD/bin" >> $GITHUB_PATH
32+
env:
33+
INPUT_OTP: ${{ inputs.otp }}
3234

3335
- name: Install NSIS
3436
shell: bash
@@ -39,15 +41,18 @@ runs:
3941
- name: Build Elixir Windows Installer
4042
shell: bash
4143
run: |
42-
export OTP_VERSION=${{ inputs.otp_version }}
43-
export ELIXIR_ZIP=$PWD/elixir-otp-${{ inputs.otp }}.zip
44+
export OTP_VERSION="$INPUT_OTP_VERSION"
45+
export ELIXIR_ZIP="$PWD/elixir-otp-${INPUT_OTP}.zip"
4446
(cd lib/elixir/scripts/windows_installer && ./build.sh)
45-
mv lib/elixir/scripts/windows_installer/tmp/elixir-otp-${{ inputs.otp }}.exe .
47+
mv "lib/elixir/scripts/windows_installer/tmp/elixir-otp-${INPUT_OTP}.exe" .
48+
env:
49+
INPUT_OTP: ${{ inputs.otp }}
50+
INPUT_OTP_VERSION: ${{ inputs.otp_version }}
4651
- name: Get ExDoc ref
4752
if: ${{ inputs.build_docs }}
4853
shell: bash
4954
run: |
50-
if [ "${{ github.ref_name }}" = "main" ]; then
55+
if [ "$GITHUB_REF_NAME" = "main" ]; then
5156
ref=main
5257
else
5358
ref=v$(curl -s https://hex.pm/api/packages/ex_doc | jq --raw-output '.latest_stable_version')

0 commit comments

Comments
 (0)