Skip to content

Artifact-cleanup steps interpolate run_id and branch into shell text rather than passing them through env #1481

Closed

Description

@ptr727

Found while settling #1473 (PR #1479). Filed rather than fixed there: the shape predates that
change and reaches the hub's own live task, so it is a fleet convention question rather than a
snippet defect.

The shape

An artifact-cleanup step passes GH_TOKEN through env:, correctly, and then interpolates two
${{ }} expressions straight into the shell text of the same run: block:

.github/workflows/build-release-task.yml:377   github.run_id, inputs.branch
catalog/snippets/workflows/publish-release.yml:111   github.run_id, github.ref_name
docs/reusable-workflows.md:548, :594   the same two, in the NuGet and PyPI stub shapes

A ${{ }} expression is substituted into the script before the shell parses it, so the value
is shell source rather than shell data. That is the reason the neighbouring GH_TOKEN goes through
env:, and the hub's own composite actions env every input they consume
(.github/actions/nuget-build-default/action.yml).

The value is attacker-shaped in principle

Git ref names permit most shell metacharacters. Measured with git check-ref-format --branch:

Branch name Result
feat/a;... valid
feat/a$(...) valid
feat/a`...` valid
feat/a|... valid
feat/a&... valid

Only space, ~, ^, :, ?, *, [ and \ are rejected, so command substitution and
statement separators both survive as legal branch names.

Reachability is low, and that is why this is not urgent

In every shape the fleet actually ships the value is a branch the attacker does not choose:

  • The release path triggers on push: branches: [main], so github.ref_name is main.
  • The smoke path reads ${{ github.base_ref || github.ref_name }}, and on a pull_request event
    base_ref is the target branch, main or develop.
  • inputs.branch in the hub task is whatever the caller stub passed, which is one of the above.

The cases that widen it are a publisher triggering on more branches than main, a
workflow_dispatch run from an oddly-named branch, and KiCadLibrary's branch-matrix dispatch,
which the reusable-workflows document already names as its own trigger shape. All of them need
push access to the repository, so this is defence in depth rather than an open door.

Why it still deserves an issue

catalog/snippets/workflows/publish-release.yml shipped in #1479 as a copy-me snapshot, and
docs/reusable-workflows.md "Adopting the Release Chain" tells an adopter
the full shape is that snippet byte for byte. So the shape now propagates to every NuGet and PyPI
adopter rather than living in one hub file, and it is inconsistent with the env: convention the
rest of the tree holds, including the very step it sits in.

Suggested remedy

Move both values to env: (RUN_ID, BRANCH) and read them as "$RUN_ID" and "$BRANCH" inside
the script, in all four locations together, so the doc block and its snippet stay byte-identical.
That is the same edit the neighbouring GH_TOKEN line already demonstrates, and it removes the
class rather than arguing about the current reachability of one instance.

The PyPI stub at docs/reusable-workflows.md:594 carries the same step and is fixed in the same
pass, per the fleet rule that settling a rule means sweeping every surface that states it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions