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 pin rewrites 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 with pins.required: true, fails a pull request that adds a tag.
  • Lock: secureci.lock and secureci inventory --check also 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.

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.

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.

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.