Pin GitHub Actions to a commit SHA and keep them updated

By the CapyShield team · · 5 min read

In short

Pin every third-party GitHub Action to its full 40-character commit SHA, because tags can be moved and a moved tag runs new code with your secrets, as the 2025 tj-actions/changed-files compromise showed. Pair pins with Dependabot's github-actions ecosystem so they get updated through reviewed pull requests. GitHub's workflow lockfiles, generally available since October 2026, record exact commits including transitive actions and supersede SHA pinning where you can adopt them.

uses: actions/checkout@v7 reads like a version number, but it isn't one. It is a git tag, and a tag can be pointed at a different commit at any time. Pinning an action to its full commit SHA is how you make sure the code you reviewed is the code that runs. This post covers why it matters, how to do it, how to keep pins current with Dependabot, and where GitHub's new workflow lockfiles fit in.

Why pin GitHub Actions to a commit SHA instead of a tag?

Because tags and branches are mutable and commit SHAs are not. GitHub resolves @v3 or @main to whatever commit that ref points to when the job starts. If the action's maintainer account is compromised, an attacker can repoint existing tags and every workflow using them runs the new code on its next build, with that workflow's secrets and token.

That is exactly what happened to tj-actions/changed-files in March 2025. Attackers retroactively modified multiple version tags to reference a malicious commit. The code read the runner's memory and printed secrets into the workflow logs, which are public in public repositories. GitHub's advisory puts the impact at over 23,000 repositories. A pinned SHA would have kept running the old, clean commit.

GitHub's own guidance says the same: pinning to a full-length commit SHA means an attacker who wanted to slip in a backdoor would need to generate a SHA-1 collision for a valid git object. Pinning to a tag is only advised if you trust the creator, and even then a tag can be moved or deleted.

How do you pin a GitHub Action to a full commit SHA?

Replace the tag with the 40-character commit it currently points to, and keep the tag in a trailing comment so people and tools can still tell which version it is:

yaml
steps:
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  - uses: capyshield-hq/capyshield/action@dd8fad936b663d4f51837fa0c60824781667f528 # v0.2.0

To look up the commit for a tag, ask the action's own repository:

terminal
git ls-remote --tags https://github.com/actions/checkout v7.0.1
# For an annotated tag, also look for a "<tag>^{}" line: that is the commit to pin, not the tag object.

Three details catch people out:

  • Use the full SHA. Only the full 40 characters is an immutable reference, and it is what GitHub's pinning guidance and SHA pinning policy check for.
  • Check it comes from the right repository. GitHub advises verifying that the SHA is from the action's repository and not a fork. Take it from the action's repository, not from a link someone pasted.
  • Pinning is one level deep. A pinned composite action can itself call other actions by tag. Pinning your uses: lines doesn't pin what those actions use, which is one reason lockfiles exist.

How do you keep pinned actions up to date with Dependabot?

A pin that never moves eventually means missing security fixes, so pair pinning with automated updates. Dependabot supports the github-actions ecosystem and understands SHA pins: it opens a pull request that moves the SHA to the new release's commit and updates the version comment next to it. Add .github/dependabot.yml:

yaml
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"            # checks .github/workflows
    schedule:
      interval: "weekly"
    cooldown:
      default-days: 7         # wait a week after a release before proposing it
    groups:
      actions:
        patterns: ["*"]       # one PR for all action bumps instead of many

The cooldown setting is worth having for actions specifically. The malicious tj-actions commit, for example, was live from March 14 to March 15, 2025. A short delay means you aren't among the first to run a release that turns out to be bad. Review each update like any other code change: read the release notes, and look at the diff between the old and new commit for anything that touches the network or the environment.

Dependabot covers reusable workflows referenced from your workflows as well as actions. Pin those by SHA too: a reusable workflow called by tag runs whatever that tag points to, with the secrets you pass it. If you maintain many repositories, put the same dependabot.yml in each of them, so no repository is left with pins nobody updates.

Are GitHub Actions workflow lockfiles better than SHA pinning?

For repositories that can adopt them, yes, according to GitHub. Workflow dependency lockfiles became generally available on October 28, 2026. A machine-generated .github/workflows/actions.lock records the exact commit for every action your onboarded workflows use, including transitive dependencies, plus the numeric owner and repository IDs. At run time GitHub runs the locked commit and checks that the repository behind the name is still the one you locked, so you can keep readable tags such as @v7.0.1 in the workflow file.

terminal
gh extension install github/gh-actions-lock   # the GitHub CLI extension that writes actions.lock
gh actions-lock                               # generate or refresh .github/workflows/actions.lock

Some limits to know:

  • Lockfiles cover actions, not reusable workflow calls (jobs.<job_id>.uses). Pin those by full commit SHA.
  • They control which action code runs, not inputs, secrets or the runner image.
  • Dependabot regenerates the matching lockfile entry in the same pull request when it bumps an action in an onboarded workflow.
  • A lock doesn't tell you whether a dependency is safe. Review before you lock.

If you use a static checker on your workflows, check whether it understands the lockfile. For example, capyshield actions checks the ref written on each uses: line, so it still reports tag refs as unpinned-uses even when a lockfile covers them.

How do you enforce SHA pinning across a repository or organization?

Since August 2025, GitHub's allowed actions policy has a setting that requires actions to be pinned to a full-length commit SHA. With it on, any workflow that uses an unpinned action fails. Administrators can set it at the enterprise, organization or repository level, and a newer Require lockfile policy does the same for lockfiles. The same policy can also block a specific action or version outright by prefixing an entry with !, which is useful during an incident.

A policy fails builds after the fact. To catch an unpinned action in review, run a check on pull requests that change workflows:

terminal
capyshield actions --fail-on high   # unpinned-uses is high: exits 4 if one is found

It skips local ./ actions, which come from your own repository, and docker:// references. For a container image, pin it by its @sha256: digest yourself. The full rule list is in the CapyShield how-it-works guide.

Frequently asked questions

Why should GitHub Actions be pinned to a commit SHA?
A tag like v3 can be repointed to any commit by whoever controls the action's repository, so a compromised maintainer account can push malicious code into every workflow that uses the tag. A full commit SHA is immutable, so the code you reviewed is the code that runs.
Does Dependabot update GitHub Actions pinned to a SHA?
Yes. With package-ecosystem: github-actions in .github/dependabot.yml, Dependabot opens pull requests that move a SHA pin to the new release's commit and update the version comment next to it.
What is a GitHub Actions workflow lockfile?
A machine-generated .github/workflows/actions.lock, created with the gh actions-lock CLI extension, that records the exact commit and repository identity for every action a workflow uses, including transitive ones. GitHub runs the locked commits even if tags move, and documents it as superseding SHA pinning for repositories that adopt it.
Can GitHub enforce SHA pinning for actions?
Yes. Since August 2025 the allowed actions policy can require actions to be pinned to a full-length commit SHA at the enterprise, organization or repository level, and workflows that use an unpinned action fail.

Sources