Skip to content

Commit 7a7c288

Browse files
EliahKaganclaude
andcommitted
ci: pass matrix values to shell scripts through the environment
zizmor's `pedantic` persona reports six `template-injection` findings, where `${{ matrix.project }}` and `${{ matrix.backend }}` are expanded directly into `run:` scripts: three steps of the `test` job in `dependencies.yml`, and the test step in `downstream.yml`. These values are constants defined in the workflows' own matrices, so nothing here is attacker-controllable. But template expansion inserts text into the script before the shell parses it, so quotation marks around a `${{ }}` expression do not neutralize quotation marks or other shell syntax inside its value. A shell expansion of an environment variable is not reparsed that way, so when it is double quoted it is always a single word. Changing the style is also preferable to turning off or suppressing the diagnostic, which would then no longer catch an expansion that does carry untrusted data. Pass each value through an environment variable named for its matrix key in upper case (`PROJECT`, `BACKEND`), and expand it double quoted, since neither word splitting nor pathname expansion is intended. Scope each variable by how many steps use it: a value used by more than one step goes in a job-level `env:` just before `steps:`, and a value used by one step goes in that step's `env:`, just before `run:`. So `PROJECT` is set for the whole `test` job in `dependencies.yml`, where three steps use it, while `PROJECT` and `BACKEND` are set only for the one step in `downstream.yml` that uses them. These are the naming, quoting, and scoping conventions gitoxide adopted for the same diagnostic. The commands receive the same arguments as before. No file in this repository reads `PROJECT` or `BACKEND`. `test/downstream/run.py` passes most of its environment through to the downstream projects' test suites, so they will also see these two variables, along with the other variables already set in CI. zizmor 1.31.1 at the `pedantic` level no longer reports any `template-injection` findings. The only remaining finding is the known `unpinned-images` finding for `alpine:latest`. `actionlint` reports no problems with either workflow. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e2d19ac commit 7a7c288

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎.github/workflows/dependencies.yml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
- python-version: "3.9"
2525
os: ubuntu-24.04
2626

27+
env:
28+
PROJECT: ${{ matrix.project }}
29+
2730
steps:
2831
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2932
with:
@@ -37,12 +40,12 @@ jobs:
3740
run: |
3841
python -m pip install --upgrade pip
3942
python -m pip install pytest flake8 ./smmap
40-
if test "${{ matrix.project }}" = gitdb; then python -m pip install ./gitdb; fi
43+
if test "$PROJECT" = gitdb; then python -m pip install ./gitdb; fi
4144
- name: Lint
42-
run: flake8 "${{ matrix.project }}/${{ matrix.project }}" --count --select=E9,F63,F7,F82 --show-source --statistics
45+
run: flake8 "$PROJECT/$PROJECT" --count --select=E9,F63,F7,F82 --show-source --statistics
4346
- name: Test
4447
run: |
45-
if test "${{ matrix.project }}" = gitdb; then
48+
if test "$PROJECT" = gitdb; then
4649
GITDB_TEST_GIT_REPO_BASE="$(git rev-parse --git-common-dir)" pytest -o addopts= -v gitdb/gitdb/test
4750
else
4851
pytest -o addopts= -v smmap/smmap/test

‎.github/workflows/downstream.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ jobs:
4848
version: '0.12.13'
4949
enable-cache: false
5050
- name: Test latest release against this checkout
51-
run: uv run test/downstream/run.py "${{ matrix.project }}" --backend "${{ matrix.backend }}"
51+
env:
52+
PROJECT: ${{ matrix.project }}
53+
BACKEND: ${{ matrix.backend }}
54+
run: uv run test/downstream/run.py "$PROJECT" --backend "$BACKEND"

0 commit comments

Comments
 (0)