Skip to content

ci(release): pass the tag through the environment, not into the script - #26

Merged
fas89 merged 1 commit into
mainfrom
ci/release-tag-through-env
Nov 21, 2026
Merged

fas89 merged 1 commit into
mainfrom
ci/release-tag-through-env

Conversation

@fas89

@fas89 fas89 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Summary

The Parse version step of .github/workflows/release.yml pasted ${{ github.event.inputs.tag || github.ref_name }} into its shell script, and the Verify version matches tag step pasted ${{ steps.meta.outputs.version }}, which is the same tag without its leading v. A tag name is chosen by whoever pushes it, and $(...) or a backtick is valid in a git ref, so such a tag ran as shell in the quality-gate job.

Both values now arrive as environment variables (TAG and TAG_VERSION), and the scripts use "$TAG" and "$TAG_VERSION". Nothing else in the scripts changes.

What changes

.github/workflows/release.yml: an env: block on each of the two steps, and the two lines that interpolated the expressions are gone. They are the only two ${{ }} expressions inside a run: script in the workflow (found by parsing the file).

Test plan

  • actionlint .github/workflows/release.yml: clean.
  • The two scripts, taken from the old and the new workflow file and run the way GitHub Actions runs them (bash -e; for the old file the expression is substituted into the script text, for the new one the value is set in the environment), with the tag v1.0.0$(touch PWNED): the old steps create the file PWNED, the new ones do not, and the version output is the literal string. The new Verify version matches tag step exits 1 on the mismatch, as it should.
  • The workflow runs only on a tag or a manual dispatch, so a pull request cannot exercise it. The scripts' logic is unchanged, so the next release is the test: quality-gate fails on a version mismatch exactly as before.

Security notes

  • Only someone who can push a tag or dispatch the workflow can supply the value, which already needs write access. Since the permissions change (fix(release): scope id-token:write to the one job that publishes #21) the quality-gate job has only contents: read, so the reach was small. This closes the pattern regardless.
  • A value in env: is data to the shell; an expression pasted into run: is code. The variables are read with shell syntax ("$TAG"), never re-expanded with ${{ env.TAG }} inside the script.
  • Not changed: github-release passes the tag to softprops/action-gh-release as an action input, not through a shell script, and the third-party actions stay at floating tags.

Borrow

Bug fix inside existing code, so there was no component to build. Checked locally: every ${{ }} expression inside a run: script in the workflow, by parsing the file (two). Read (from search results, not in full): GitHub's secure-use reference, which says to set the untrusted value in the step's env: and read it with native shell syntax (https://docs.github.com/en/actions/reference/security/secure-use), and CodeQL's query help for code injection in Actions, which gives the same fix and warns against re-expanding the variable with ${{ env.X }} (https://codeql.github.com/codeql-query-help/actions/actions-code-injection-medium/).

The Parse version step pasted ${{ github.event.inputs.tag || github.ref_name }} into its
shell script, and the Verify version step pasted ${{ steps.meta.outputs.version }}, which
is the same tag without its leading v. A tag name is chosen by whoever pushes it, and
$(...) or a backtick is valid in a git ref, so such a tag ran as shell in the quality-gate
job. Only someone with write access can push a tag or dispatch the workflow, and the job
has only contents: read since the permissions change, so the reach was small; it is still
the pattern GitHub's own guidance says to avoid.

Both values now arrive as environment variables (TAG and TAG_VERSION) and the scripts use
"$TAG" and "$TAG_VERSION". The scripts are otherwise unchanged. Run with a tag of
v1.0.0$(touch PWNED), the old steps create the file and the new ones do not.
@fas89
fas89 merged commit 452eb50 into main Nov 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant