Updated 4 min read

Pin GitHub Actions to a commit SHA

In March 2026 attackers rewrote almost every version tag of trivy-action to steal CI secrets. Why version tags aren't safe, and how to lock down your workflows.

GitHub Actions workflow snippet highlighting a third-party action pinned to a commit SHA.

Most GitHub Actions workflows reference third-party actions like this:

- uses: aquasecurity/[email protected]

It looks like a fixed version. It isn’t. v0.34.0 is a Git tag, and a Git tag is a movable pointer: anyone with write access to the repository can make it point at a different commit. Your workflow will run whatever code the tag points to at the moment the job starts — with access to your secrets.

Advertisement

In March 2026 that stopped being a theoretical risk.

What happened to trivy-action

Trivy is a widely used open-source security scanner, and aquasecurity/trivy-action is the official way to run it in GitHub Actions — a tool people add to their pipelines precisely to make them safer.

According to Aqua Security’s own write-up, on 19 March 2026 an attacker force-pushed 76 of the 77 version tags of trivy-action, plus the tags of setup-trivy, to malicious commits. (Snyk’s analysis counts 75 of 76; the order of magnitude is the point.) The payload stole CI/CD secrets and then ran the legitimate Trivy scan, so affected pipelines kept passing and looked normal.

Aqua traced the entry point to a misconfiguration in Trivy’s own GitHub Actions environment in late February, and found that a credential rotation on 1 March had been incomplete, which let the attacker keep access. Malicious artifacts were removed on 19 March, with safe versions and indicators of compromise published the next day.

Two details are worth sitting with:

  • The version you pinned didn’t matter. v0.20.0 or v0.34.0 — if your workflow referenced a tag, it ran the attacker’s code.
  • The only version left untouched, v0.35.0, was protected by GitHub’s immutable releases feature, which prevents a release’s tag from being moved.

Workflows that referenced the action by full commit SHA kept running exactly the code their authors had chosen.

Tags, branches and SHAs

ReferenceExampleCan it change?
Branch@mainYes — every new commit
Version tag@v3, @v0.34.0Yes — the tag can be moved
Full commit SHA@57a97c7e7821a5776cebc9bb87c984fa69cba8f1No

A commit SHA is derived from the content of the commit. You cannot make an existing SHA point at different code. That is the whole property you want.

How to pin

Look up the commit a release tag points to (on GitHub’s release page, or with git ls-remote), then reference it with the version as a comment so humans can still read it:

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
git ls-remote --tags https://github.com/aquasecurity/trivy-action 'v0.36.0*'
# a9c7b0f0…  refs/tags/v0.36.0       ← the tag object
# ed142fd0…  refs/tags/v0.36.0^{}    ← the commit: pin this one

Watch out for that second line. Most release tags are annotated: the tag is its own Git object that points at a commit. Without ^{}, ls-remote shows the tag object’s hash, which is not what uses: should reference. For a lightweight tag only one line appears, and it is already the commit.

Pinning does not mean freezing. Dependabot understands SHA-pinned actions: enable the github-actions ecosystem and it opens pull requests that bump both the SHA and the version comment. You still get updates — but each one goes through a reviewed pull request instead of arriving silently.

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: github-actions
    directory: /
    schedule:
      interval: weekly

Pinning is necessary, not sufficient

A pinned action cannot change under you, but it still runs with whatever access your workflow gives it. Shrink that access too:

Read-only token by default. Set permissions: contents: read at the top of every workflow and grant more per job only where needed. A compromised step can only steal what the token allows.

permissions:
  contents: read

jobs:
  image:
    permissions:
      contents: read
      packages: write

Don’t leave credentials on disk. By default actions/checkout keeps the token on the runner’s disk, configured for Git, so later steps can push. Most jobs never push:

- uses: actions/checkout@<sha> # v7
  with:
    persist-credentials: false

Scope secrets to environments. Put deployment credentials in a protected production environment so only the deploy job can read them, optionally behind required reviewers.

Prefer OIDC to long-lived cloud keys. With id-token: write, a job can exchange a short-lived GitHub token for temporary cloud credentials. There is no permanent key in your secrets to steal in the first place.

Never print secrets. Pass them through env: instead of interpolating ${{ secrets.X }} directly into shell commands, where they can leak into logs or be broken out of with crafted input.

What to do if you were exposed

If any workflow ran a compromised action, assume every secret available to that job was read:

  1. Find the runs in the exposure window and list the secrets each job could access.
  2. Rotate all of them — registry tokens, cloud credentials, deploy keys, API tokens.
  3. Check the vendor’s published indicators of compromise against your logs.
  4. Then pin the action by SHA so the next incident can’t reach you the same way.

The takeaway

The uncomfortable lesson of March 2026 is that the attack came through a security tool. Trust in a project is not a substitute for verifying which code you run. Pin third-party actions to commit SHAs, keep them updated through reviewed pull requests, and give every job the least access it needs.

For how these practices fit into a complete pipeline, see a production CI/CD pipeline with GitHub Actions.

Sources