Harden the container checkout: no template expansion inside run
Build PCM package / build (push) Successful in 6s
tests / ubuntu-latest · py3.11 (push) Successful in 1m59s
tests / ubuntu-latest · py3.13 (push) Successful in 1m8s
tests / debian:12 (push) Successful in 53s
tests / archlinux:latest (push) Successful in 45s
tests / fedora:latest (push) Successful in 1m2s
tests / ubuntu:24.04 (push) Successful in 2m7s
tests / NixOS (FHS wrapper from docs/NIXOS.md) (push) Has been skipped
tests / macos-latest · py3.11 (push) Has been cancelled
tests / macos-latest · py3.13 (push) Has been cancelled
tests / windows-latest · py3.11 (push) Has been cancelled
tests / windows-latest · py3.13 (push) Has been cancelled

github.ref reaches the shell via env instead of ${{ }} interpolation
- a crafted PR branch name could otherwise inject commands into the
runner - and ref/sha formats are validated before git sees them.
This commit is contained in:
2026-07-23 17:33:50 +07:00
parent f68c14b01c
commit 72bb46e9b5
+14 -4
View File
@@ -94,13 +94,23 @@ jobs:
- name: Distro Qt runtime libraries + git - name: Distro Qt runtime libraries + git
run: ${{ matrix.setup }} run: ${{ matrix.setup }}
# Plain-git checkout: works in any container with git alone. # Plain-git checkout: works in any container with git alone.
# (A private repo would need ${{ github.token }} on the URL.) # (A private repo would need github.token on the URL.) Values
# arrive via env, not ${{ }} in the script: a template expansion
# inside `run:` would let a crafted PR branch name inject shell
# commands into the runner.
- name: Checkout - name: Checkout
env:
SERVER_URL: ${{ github.server_url }}
REPO: ${{ github.repository }}
REF: ${{ github.ref }}
SHA: ${{ github.sha }}
run: | run: |
case "$REF" in refs/heads/*|refs/tags/*|refs/pull/*) ;; *) echo "unexpected ref: $REF"; exit 1;; esac
case "$SHA" in *[!0-9a-f]*|"") echo "unexpected sha"; exit 1;; esac
git init -q . git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git" git remote add origin "$SERVER_URL/$REPO.git"
git fetch -q --depth 50 origin "${{ github.ref }}" git fetch -q --depth 50 origin "$REF"
git checkout -q "${{ github.sha }}" git checkout -q "$SHA"
- name: Install uv - name: Install uv
run: | run: |
curl -LsSf https://astral.sh/uv/install.sh | sh curl -LsSf https://astral.sh/uv/install.sh | sh