Sub topic 1
What a `uses:` Reference Points To
Prerequisites
Assume you know basic GitHub Actions workflow syntax, including jobs, steps, and uses:. You should also know that Git commits have SHA identifiers and that tags such as v4 name releases.
What a `uses:` Reference Points To
A uses: value selects reusable code for a workflow step. Its common form is:
- uses: OWNER/REPOSITORY@REFREF can be a branch, a tag, or a commit SHA.
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@main
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683The first reference selects the v4 tag. The second selects the current tip of the main branch. The third selects one exact commit.
Why Tags and Branches Are Risky
Branches move whenever new commits are added. Tags are usually treated as stable release names, but a maintainer with sufficient repository permissions can move a tag to another commit. An attacker who gains write access could also repoint it.
The workflow file would remain unchanged, but a later run could download different code. If that action can read secrets or modify build artifacts, the changed code could affect the whole pipeline.
Pinning an Action to a Full-Length Commit SHA
A full-length commit SHA identifies one Git commit. Pinning to it makes the selected action code stable until someone reviews and changes the workflow.
steps:
# Mutable reference
- uses: actions/checkout@v4
# Immutable reference, with a readable release comment
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2The comment helps reviewers and update tools understand which release the SHA represents. It does not affect GitHub Actions.
Finding and Verifying the SHA for a Release
Resolve the tag from the intended repository. For an annotated tag, the ^{} result is the commit that the tag ultimately names.
git ls-remote https://github.com/actions/checkout \
'refs/tags/v4.2.2' 'refs/tags/v4.2.2^{}'Compare the returned commit with the SHA in your workflow. Check the repository owner and name carefully. A valid SHA from a fork or an impostor repository is still the wrong dependency.
Exercise
Why is a full-length commit SHA safer than @v4?
Show answer
The SHA identifies one exact commit, while the v4 tag can be moved to different code.