Sub topic 14
Third-party actions and SHA pinning
This chapter assumes you can read a GitHub Actions workflow (events, jobs, steps), know what GITHUB_TOKEN and repository secrets are, and have seen the pull_request and pull_request_target triggers from earlier chapters. Earlier chapters dealt with attacker-controlled data flowing into your workflow. This chapter covers a different input: the code of the actions you choose to run.
Why an action is code you execute
A step with uses: downloads someone else's code and runs it inside your job. That code runs with the same access as your own run: steps:
- It can read every secret you pass to that step through
env:orwith:. - It can use the
GITHUB_TOKENwith whatever permissions the job has. - Because it runs on the same runner, it can read files that earlier steps wrote. It can also modify files that later steps use.
- It can write to
GITHUB_ENVandGITHUB_PATH, which changes how later steps behave.
So a workflow that is safe against script injection can still be compromised if one of its actions is malicious or gets hijacked. The trust you place in the action's author, and in everyone who can push to the action's repository, becomes part of your trust model.
What a version reference points to
The text after @ in a uses: line is a Git ref. It can be a branch, a tag, or a full commit SHA.
| Reference | Example | Who controls what it points to | Risk |
|---|---|---|---|
| Branch | `owner/action@main` | Anyone with push access to the action's repository | Changes on every push. Highest risk. |
| Tag | `actions/checkout@v4` | The maintainers. Tags can be moved or deleted and recreated. | Mutable, so the code behind `v4` can change without any change in your repository. |
| Full commit SHA | `actions/checkout@<40-character SHA>` | Nobody. A commit's content is fixed by its hash. | Immutable. Safest. |
The important fact is that a tag is a pointer, and pointers can be repointed. If an attacker gains write access to an action's repository, they can move an existing tag such as v1 to a malicious commit. Every workflow that references @v1 then runs the attacker's code on its next run, with no pull request, no review, and no diff in your repository.
This has happened in practice. In March 2025, the widely used tj-actions/changed-files action was compromised. Its tags were repointed to a commit that printed secrets from the runner's memory into the workflow logs. Repositories that referenced a version tag ran the malicious code. Repositories that pinned a SHA from before the compromise did not.
Pinning to a commit SHA
Pinning means replacing the tag with the full 40-character commit SHA. Add a comment with the human-readable version so reviewers and update tools know what it represents.
name: ci
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
# Mutable: the tag can be moved to different code
# - uses: actions/checkout@v4
# Pinned: this exact commit is always used
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- run: npm ci && npm testThree details matter:
- Use the full SHA. Short SHAs are not accepted for
uses:in a way you should rely on. A short prefix can also collide with another object, so always use all 40 characters. - Get the SHA from the action's official repository. Look up the commit that the release tag points to. For annotated tags, make sure you take the commit SHA and not the SHA of the tag object itself.
- Verify that the commit belongs to the repository you expect. Forks share commit storage with their parent repository on GitHub. A commit SHA that is not part of the original repository's history can still resolve under the original repository's name if it exists in a fork. This is sometimes called an impostor commit. Check that the SHA appears in the history of a branch or a release tag of the real repository, not only that the URL loads.
You can resolve a tag to its commit with the Git command line:
git ls-remote https://github.com/actions/checkout.git 'refs/tags/v4.2.2*'If the output shows two lines, one ending in v4.2.2 and one ending in v4.2.2^{}, the second line (with ^{}) is the commit that the annotated tag points to. Use that SHA.
What pinning does not fix
Pinning protects you from a changed reference. It does not make the pinned code safe.
- You still run whatever was at that commit. If the commit was already malicious or vulnerable when you pinned it, you now run it permanently.
- Nested dependencies. A composite action can call other actions with
uses:, and those inner references may use mutable tags. A JavaScript action bundles or downloads npm packages. A Docker action may pull an image by tag. Your pin on the outer action does not control any of this. Reading the action'saction.ymlshows what it pulls in. - Staleness. A pinned SHA never receives bug fixes or security patches unless you update it. You need a process for updates.
Because of the last point, pair pinning with an update tool. Dependabot supports the github-actions ecosystem and opens pull requests that bump SHA-pinned actions and update the version comment:
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"Save this as .github/dependabot.yml. Review each update pull request as you would a code dependency change, by reading the diff between the old and new commits.
Trust levels of action sources
Not all third-party actions carry the same risk. A practical way to decide is to sort them by who publishes them.
| Source | Example | Suggested handling |
|---|---|---|
| Published by GitHub | `actions/checkout`, `actions/cache` | Pin to SHA. Lowest risk, but still pin. |
| Verified or well-known organizations with many maintainers | Cloud provider login actions | Pin to SHA. Review release notes on update. |
| Small, single-maintainer actions | A personal repository with a handy utility | Read the source. Pin to SHA. Consider copying the logic into a `run:` step or forking the repository into your organization. |
| Unreviewed or unmaintained actions | An action not updated in years | Avoid. Replace it. |
Many actions do little that a few lines of shell cannot do. If an action only wraps a single CLI call, calling that CLI yourself removes a dependency.
Combining pinning with the rest of the model
Pinning is one layer. The earlier defenses reduce the damage when an action misbehaves.
- Least privilege. Set
permissions:at the workflow or job level so a compromised action receives a token that can only read contents. - Limit secrets to the steps that need them. Put a secret in the
env:of one step, not the whole job. Any action in the job can read job-level environment variables. - Keep third-party actions out of privileged jobs. In a
pull_request_targetorworkflow_runjob that holds write permissions or secrets, everyuses:line is part of the attack surface. Prefer first-party actions andrun:steps there. - Separate jobs. Run risky or less-trusted actions in an unprivileged job with no secrets. Pass only the results you need to a later job, and treat those results as untrusted input.
The following workflow shows the least-privilege approach in a job that uses a third-party action. The action receives no secrets, and the token is read-only.
name: lint
on: pull_request
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: example-org/lint-action@0123456789abcdef0123456789abcdef01234567 # v2.1.0The persist-credentials: false setting stops actions/checkout from leaving the token in the local Git configuration, where a later step could read it. The example-org/lint-action reference and its SHA are placeholders. Replace them with a real action and a SHA you have verified.
Enforcing pinning
Good habits fade, so enforce the rule.
- Organization or repository policy. In the Actions settings, an administrator can restrict which actions may run. You can allow only actions from your own organization, GitHub-created actions, verified creators, or a specific allow list. GitHub also offers a policy option that requires actions to be pinned to a full commit SHA, so a workflow that uses a tag fails.
- Audit tools. Scanners such as
zizmorandpinact, and the OpenSSF Scorecard check for pinned dependencies, reportuses:lines that are not pinned to a SHA. Chapter 14 covers these tools in more detail. Run one in CI so a new unpinned reference fails the build. - Code review. Changes to files under
.github/workflows/should require review from people who understand this model. A CODEOWNERS entry for that path makes the requirement explicit.
# .github/CODEOWNERS
/.github/workflows/ @your-org/security-reviewersCommon mistakes
- Pinning with a tag you believe is stable, such as
v4. Major-version tags are the ones maintainers move on purpose. - Copying a SHA from a blog post or a search result without checking it against the real repository.
- Pinning the outer action and forgetting that its composite steps or Docker image use mutable references.
- Pinning once and never updating, which leaves known vulnerabilities in place.
- Using
@mainfor a quick test and leaving it in.
Exercise
A workflow uses uses: some-org/deploy-action@v2 in a job that has a deployment secret in its env:. A maintainer's account for some-org is compromised and the v2 tag is moved to a malicious commit. Name two changes that would have reduced the harm, and explain why pinning alone might still leave a gap if the action is a composite action.
Show answer
First, pin the action to the full commit SHA of a reviewed release, so moving the tag has no effect. Second, limit the secret's exposure, for example by placing it only in the env: of the single step that needs it and setting minimal permissions: on the job. Pinning alone can leave a gap because a composite action can call other actions or download tools using mutable references (tags or branches). Those inner references are not covered by the SHA of the outer action, so the attacker could change what they point to. You must review the composite action's action.yml and its nested dependencies.
Exercise
You find uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac in a workflow, but the SHA is not part of any release or branch in the real actions/checkout repository. What could this be, and how do you check?
Show answer
It could be an impostor commit: a commit that exists in a fork of the repository but not in the original. Because forks share commit storage, the SHA can resolve under the original repository's name. To check, confirm that the SHA is reachable from a branch or release tag of the real repository (for example, compare it with the commit shown for a known release tag using git ls-remote or the repository's releases page), and replace it with a verified SHA.