CCyberwiki

Pinning to commit hashes

Pinning to commit hashes
TypeSupply chain control
Also known asSHA pinning, digest pinning
Applies toGitHub Actions uses: lines, reusable workflow calls, container image references
CWECWE-829: Inclusion of Functionality from Untrusted Control Sphere
OWASP Top 10A03:2025
RelatedLockfile, Dependabot

A step in a GitHub Actions Workflow (GitHub Actions) names the code it runs with a line such as uses: actions/checkout@v6. The part after the @ is a Git reference, and when it is a tag or a branch, GitHub resolves it to whatever commit it points to at the moment the run starts.1 Pinning replaces that reference with the full hash of one commit, so every run executes the same code even if the tag is later moved. Container images work the same way: the tag alpine:3.21 can be pointed at a new image, while an image digest cannot.2

Tags and hashes

A Git tag is a label. Anyone who gains write access to the repository that holds an action can move the label to another commit or delete it.3 A commit hash cannot be moved that way: to put different code behind a hash that a workflow already uses, an attacker would have to produce a SHA-1 collision for a valid Git object.3 A pinned workflow therefore does not pick up code that is added to a new or rewritten tag or branch.4 The code behind a moved tag runs with the action's access, which covers every secret configured on the repository and may include the job's token with write rights, the risk Secret exposure in CI/CD workflows describes.3

The tj-actions case

On 14 and 15 March 2025, attackers rewrote several version tags of tj-actions/changed-files, an action used by more than 23,000 repositories, so that they pointed at one malicious commit; v1.0.0, v35.7.7-sec and v44.5.1 were among them. The new code downloaded a Python script that searched the memory of the runner worker process for secrets and printed them, encoded, into the build log, where anyone could read them in a public repository.5 A workflow that referred to one of those tags ran the malicious commit on its next run without any change to its own file.51

The advisory for CVE-2025-30066 rates it High, 8.6 out of 10. It told anyone who had pinned the malicious commit's hash to replace it, since a pin holds whatever commit it names. Workflows that used the tags needed no edit once the tags were restored, but any secret that could have leaked in those two days was to be rotated.5

Pinning a workflow step

steps:
  # Tag: resolved again on every run
  - uses: actions/checkout@v6
  # Full commit hash: always the same code
  - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3

The hash to use is the commit of a released version, which GitHub calls the safest reference for stability and security.6 It must be complete. Short forms such as actions/checkout@5a4ac90 stopped working on 15 February 2021.7 Copy the hash from the action's own repository and not from a fork.3

The version can be kept as a comment at the end of the same line, in the form actions/checkout@<commit> # <tag>; Dependabot updates that comment when it moves the hash.3 Calls to reusable workflows with jobs.<job_id>.uses accept a hash, a tag or a branch. When a tag and a branch share a name, the tag is used, and the hash is again the safe choice.6

Container images

Docker image tags are mutable by design, which lets a publisher move a tag such as 3.21 to a newer build.2 Adding the digest to the reference fixes the image: the pull returns the same build even after the publisher has replaced the tag.28

# Dockerfile: tag for readers, digest for the build
FROM alpine:3.21@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c

docker pull prints the digest after it downloads an image.8 For an image published for several CPU architectures, the digest of the manifest list can be pinned in place of the digest of one platform's image.9

Keeping pins current

A pin also holds back fixes. Pinning a digest opts out of the security updates that a moving tag would bring, and looking up digests by hand is slow.2 For actions, Dependabot alerts cover only references written as a semantic version; an action pinned to a hash gets no alert.3

Dependabot version updates open pull requests that move a pinned hash to a newer release and rewrite the version comment. If the pinned commit carries no tag, Dependabot moves it to the newest commit, which may not be a release. It does not update docker:// references inside workflows.3 Configured for Docker, it updates base image tags and digests on a schedule, so every change arrives as a reviewed pull request.2

Lockfiles and enforcement

A hash in a workflow file fixes only the action on that line. GitHub's workflow dependency lockfile, .github/workflows/actions.lock, records the resolved commit of every action a workflow depends on, including the actions those actions use. The gh actions-lock extension for the GitHub command line generates it, and the file is never edited by hand. Each entry stores the tag or branch, the commit, and numeric owner and repository IDs. At run time GitHub checks that the name still belongs to the same repository and that the commit is reachable from the recorded tag or branch there, so a commit that exists only in a fork is rejected.1

With a lockfile, workflow files can keep readable tags. It does not pin calls to reusable workflows, which still need a full hash, and it has no say over secrets, inputs or the runner image.1 GitHub's security guidance ranks it above hash pinning for repositories that adopt it.3

Since 15 August 2025, the allowed actions policy at enterprise, organization and repository level has a setting that fails any workflow using an action not pinned to a full commit hash, and an entry starting with ! blocks a named action or version.4 A workflow covered by a lockfile passes that policy without hashes in its file.1

On the publisher's side, an immutable release locks its Git tag to one commit: the tag cannot be moved or deleted while the release exists, and its name cannot be used again.10 The OpenSSF Scorecard check Pinned-Dependencies, which looks for unpinned references in Dockerfiles, shell scripts and workflows, counts a tag backed by an immutable release as pinned.9

Prompt for a coding agent

Go through every file in .github/workflows and every Dockerfile and docker-compose file in this project. Replace each third-party uses: reference that names a tag or branch with the full commit hash that tag points to today, copied from the action's own repository, and keep the tag as a comment on the same line. Do the same for reusable workflow calls. Add the sha256 digest to every image reference in FROM and image: lines, keeping the tag in front of it. Add a Dependabot configuration with github-actions and docker entries so the pins get update pull requests. List every line you changed and any reference you could not resolve.

In SecFlash

SecFlash reports a workflow step that uses an action by tag or branch as SF-SEC-806 on the Security page. A Dockerfile FROM line with no tag or with latest shows as SF-CLD-901, and the same problem in a Compose file as SF-CLD-910, both on the Cloud page.

See also

References

  1. a b c d e GitHub (2026). "Workflow dependency lockfiles". GitHub Docs.
  2. a b c d e Docker. "Building best practices", section "Pin base image versions". Docker Docs.
  3. a b c d e f g h GitHub (2026). "Secure use reference". GitHub Docs.
  4. a b GitHub (15 August 2025). "GitHub Actions policy now supports blocking and SHA pinning actions". GitHub Changelog.
  5. a b c GitHub (15 March 2025, updated 22 October 2025). "tj-actions changed-files through 45.0.7 allows remote attackers to discover secrets by reading actions logs" (GHSA-mrrh-fwg8-r2c3, CVE-2025-30066). GitHub Advisory Database.
  6. a b GitHub. "Workflow syntax for GitHub Actions". GitHub Docs.
  7. back GitHub (21 January 2021). "GitHub Actions: Short SHA deprecation". GitHub Changelog.
  8. a b Docker. "docker image pull". Docker Docs, CLI reference.
  9. a b OpenSSF. "Check Documentation", section "Pinned-Dependencies". OpenSSF Scorecard.
  10. back GitHub. "Immutable releases". GitHub Docs.