How to pin GitHub Actions to a commit SHA
Last reviewed: 23 November 2026, against SecureCI CLI 1.4.0
To pin a GitHub Action, replace its tag with the full 40-character commit SHA the tag points at. Keep the tag as a comment, so uses: actions/checkout@v4 becomes uses: actions/checkout@<sha> # v4. A tag can be moved to different code at any time. A commit SHA can’t. SecureCI’s free, open-source CLI does this for every workflow with one command, secureci pin. It can then enforce pinning in CI and lock what pinning misses.
Short answer:
- Pin:
secureci pinrewrites tags to SHAs in place and keeps the tag as a comment for Dependabot and Renovate (since v0.6.0). - Enforce:
secureci pin --check, or a contract withpins.required: true, fails a pull request that adds a tag. - Lock:
secureci.lockandsecureci inventory --checkalso cover the actions inside your actions and re-created repositories (since v0.5.0).
Why tags are not immutable
A Git tag is a name that points at a commit. Whoever controls the repository can move it. So the code behind @v4 today may not be the code that runs tomorrow.
GitHub’s own secure use reference makes the same point. It warns that “a tag can be moved or deleted” if a bad actor gains access to the repository. It also tells you to pin actions to a commit SHA.
In March 2025 this happened to tj-actions/changed-files. Attackers changed multiple of its version tags to point at a malicious commit. Between 14 and 15 March, workflows that used one of those tags ran that commit. It dumped CI secrets into the build logs. The GitHub advisory (CVE-2025-30066) puts the number of affected repositories at over 23,000. Workflows pinned to an earlier, reviewed SHA kept running the code they had before.
Pin by hand, and why it doesn’t scale
To pin one action yourself, look up the commit behind the tag:
git ls-remote https://github.com/actions/checkout refs/tags/v4
The first column is the SHA. For an annotated tag, git prints a second line that ends in ^{}. That line holds the commit, so use it. Then edit the workflow:
- uses: actions/checkout@v4
# becomes
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
GitHub advises you to check that the SHA comes from the action’s own repository, not from a fork. Looking the tag up in the real repository, as above, avoids copying a SHA from a fork.
This works for one file. It gets hard across a real codebase. Each workflow, local composite action and reusable workflow call needs the same edit. Every update repeats the lookup. One missed line or wrong SHA is easy to make and hard to spot in review.
Pin every workflow with secureci pin
Install the SecureCI CLI (secureci) with npm install -g @secureci/cli (Node.js 20+), or download a standalone binary. Then run it from the repository root:
# every file in .github/workflows, plus the local
# actions and reusable workflows they use
secureci pin
# just this file
secureci pin .github/workflows/ci.yml
# use only the action cache, no network
secureci pin --offline
It rewrites each tag or branch to the commit it points at now. It keeps the tag in a trailing comment, as in the example above. Review the diff, then commit it.
- What it pins: step
uses:lines in workflows and in local composite actions, and reusable workflow calls. - What it leaves alone: local (
./) anddocker://references, and references already pinned to a 40-character SHA. - Formatting stays: files are edited in place, never re-serialised. Only the value and its comment change, and a second run changes nothing.
- Comments: an old version comment such as
# v3is replaced. Any other comment is kept after the tag. - Lookups: it uses
git ls-remote, or the GitHub API when a token is set (GITHUB_TOKEN,GH_TOKENorgh auth token). - Failures are visible: a reference it can’t resolve, such as a deleted repository, is reported with its file and line and left unchanged.
Starting a new repository? secureci init workflow writes a pull request checks workflow with every action already pinned to a SHA (since v0.10.0). Pass --no-pin to keep tags.
Keep pins updated
A pinned SHA never changes, so neither do the fixes you get. You still need updates. That is why secureci pin keeps the tag comment: Dependabot and Renovate can still offer updates for pinned actions.
To turn on Dependabot for GitHub Actions, commit a config like this:
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
Treat each update as a code change. A pin protects you only if someone looked at the commit it points to. After you merge an update, refresh the lockfile with secureci inventory --update-lock and commit the diff.
Enforce pinning in CI
Pinning once is not enough. The next pull request can add a tag again. There are two ways to stop that.
The simple check is secureci pin --check. It writes nothing. It exits non-zero if any reference would be pinned or can’t be resolved.
For a shared standard, use a pipeline contract. It can require pins, trust some owners by tag, and limit which owners you use at all:
# contracts/standard.yml
pins:
required: true # every remote action must be pinned to a 40-char commit SHA
allow:
- actions # trust these owners (or owner/repo) by tag
allowed-owners: # if set, every remote action's owner must be listed
- actions
- my-org
secureci validate .github/workflows/*.yml --contract contracts/standard.yml
An unpinned action is an error, reported at the step’s call path. The rule is checked through local composite actions and reusable workflows, so a tag can’t hide inside a wrapper. Add --contract-recurse all to inspect remote ones too. Local and docker:// references are exempt. If you trust some owners by tag, run secureci pin --contract contracts/standard.yml. It leaves those owners on their tags, so the contract check passes afterwards.
To run both checks on every pull request, add the SecureCI GitHub Action. Reference it by an exact release, pinned like any other action:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: secure-ci/cli@a8bc54904c21f09b96a80850c557fdaa5f92abb6 # v1.4.0
with:
contract: contracts/standard.yml
inventory: check
inventory: check needs a committed secureci.lock. The next section shows how to create one.
The action uploads SARIF to code scanning by default. That needs actions: read and security-events: write on the job, and code scanning on for the repository. Otherwise, set upload-sarif: false. The CI docs have the full workflow.
GitHub’s allowed-actions policy can also require SHA pinning. Turn it on as a baseline. The SecureCI check adds a failing pull request before merge, the same answer on a developer’s laptop, and per-owner exceptions in a file you review like code.
What SHA pinning does not cover
Critics of SHA pinning have a point. A pin fixes the lines in your own workflow, and nothing else. GitHub now says a workflow lockfile is the strongest protection, ahead of SHA pinning. Here is what a pin leaves open, and what covers each gap.
- Actions inside actions. A composite action or reusable workflow you pin has its own
uses:lines. If they use tags, a moved tag still runs new code inside your pinned action.secureci inventoryfollows remote composite actions and reusable workflows, up to 10 levels deep, and locks what they use too (since v0.5.0). - Re-created repositories. A pin names a repository by owner and name. If that repository is deleted and someone re-creates it, the name points at new code (repo-jacking). When the GitHub API answers,
secureci.lockrecords GitHub’s numeric ids for each repository and owner. A changed id fails the check even when the commit matches. - Repositories that disappear. If a pinned action’s repository is deleted, renamed or made private, the check fails and names it (since v0.5.1).
- Code fetched at run time. Node and Docker actions have no
uses:lines to follow. Anything they download while they run is outside any lock ofuses:references. SecureCI doesn’t monitor runners at run time. - A bad commit. Pinning freezes code. It doesn’t vet it. Review an action before you trust it.
secureci validatealso flags actions with known advisories from the GitHub Advisory Database (since v0.6.0).
The lockfile is what closes the first three gaps:
# writes secureci.lock the first time,
# drift-checks on later runs
secureci inventory
# in CI: fails when a locked tag now points at different code
secureci inventory --check
Commit secureci.lock like package-lock.json. It is plain JSON, so changes show up in review. A contract can also require every repository to commit one, with lockfile: { required: true }.
On GitHub.com, a repository can also use GitHub’s workflow lockfiles (public preview since October 2026). When actions.lock is a repository’s only lockfile, secureci inventory --check verifies against it (since v0.3.0), so the same check runs on a laptop and on every pull request. secureci.lock also works on GitHub Enterprise Server, where actions.lock isn’t available.
Pinning across many repositories
One repository is a short job. A whole organisation needs one standard and a view of who meets it.
- One contract for every team. Keep it in a central repository and point each check at it, for example
--contract my-org/standards/contracts/standard.yml@<sha>(since v0.4.0). The enforced commit is recorded in the report. - One scan for every repository.
secureci org scan <org>validates and inventories every repository in an organisation, with JSON results only (since v1.1.0). - Evidence for audits. Pinned actions and a committed lockfile support controls such as PCI DSS 6.3.2 (an inventory of third-party components) and NIS2 supply chain security. See the compliance mapping for what SecureCI supports and what it doesn’t cover.
The org-wide SecureCI platform is in development. Continuous monitoring and drift alerts aren’t available yet. Today, each repository catches its own moved tags with secureci inventory --check. Pilot organisations can request a free supply-chain assessment. You run the open-source CLI in your own infrastructure and send only the JSON results, never source code.
Pin one repository with the free CLI
Free and open source (MIT). Needs Node.js 20+.
npm install -g @secureci/cli
secureci pin
secureci inventory
Running GitHub Actions across many repositories? Get early access to the GitHub App → or get a free assessment.
FAQ
How do I find the commit SHA for a tag?
Run git ls-remote with the action’s repository URL and the tag, for example git ls-remote https://github.com/actions/checkout refs/tags/v4. The first column is the SHA. For an annotated tag, use the line that ends in ^{}, which is the commit. secureci pin does the same lookup for you, with git ls-remote or the GitHub API.
Does Dependabot update pinned actions?
Turn on Dependabot version updates for the github-actions ecosystem. secureci pin keeps the tag in a trailing comment so that Dependabot and Renovate can still offer updates. Review each update before you merge it, then refresh secureci.lock.
Is SHA pinning enough?
No. A pin covers the lines in your own workflow. It doesn’t cover the actions that a pinned action uses, a repository that is deleted and re-created under the same name, or code an action downloads while it runs. secureci.lock and secureci inventory --check cover the first two, and the check also verifies GitHub’s actions.lock when that is a repository’s only lockfile.
Does secureci pin change my YAML formatting?
No. Files are edited in place, never re-serialised. Only the value and its trailing comment change. Blank lines, other comments and key order stay as they are, and running secureci pin again changes nothing.
Should I use GitHub’s actions.lock or secureci.lock?
SecureCI works with either. When GitHub’s actions.lock (GitHub.com, public preview since October 2026) is your only lockfile, secureci inventory --check verifies against it. secureci.lock works everywhere, including GitHub Enterprise Server, where actions.lock isn’t available.
Sources
We checked these on 15 November 2026. If something here is out of date, email [email protected] and we’ll fix it.
- GitHub advisory GHSA-mrrh-fwg8-r2c3: tj-actions/changed-files (CVE-2025-30066)
- GitHub docs: secure use reference for GitHub Actions
- GitHub docs: workflow dependency lockfiles
- GitHub changelog: Actions policy supports blocking and SHA pinning (Aug 2025)
- GitHub docs: keeping your actions up to date with Dependabot
- SecureCI CLI documentation
- SecureCI compliance mapping