Sub topic 15
Auditing workflows with automated tools
This chapter assumes you can read a GitHub Actions workflow file. It also assumes you know the injection and pull_request_target patterns from the earlier chapters. You should be comfortable running commands in a terminal.
Why audit with tools
Reviewing workflows by eye works for one file. It stops working across dozens of repositories, or when a new contributor adds a step that interpolates ${{ github.event.pull_request.title }}. Static analyzers read the YAML and flag patterns you already know are dangerous. Because they run in seconds, you can run them on every pull request.
Two properties of workflow files make this practical:
- Workflows are declarative. Triggers, permissions,
uses:references andrun:bodies are all visible in the file. - The dangerous patterns are syntactic. An untrusted
github.event.*expression inside arun:block, orpull_request_targetcombined with a checkout of the PR head, can be matched without executing anything.
The tool landscape
| Tool | What it does | Typical use |
|---|---|---|
| actionlint | Linter for workflow syntax, types and expressions. It also warns when untrusted inputs appear in `run:` and in the `script:` input of `actions/github-script`. | Fast local and CI lint |
| zizmor | Security-focused static analyzer for workflows. Its audits cover template injection, dangerous triggers, excessive permissions, unpinned actions and `GITHUB_ENV` misuse. | Main security gate |
| poutine | Static analyzer for build pipelines, including GitHub Actions. It reports injection and untrusted checkout. | Second opinion, org-wide scans |
| OpenSSF Scorecard | Scores a repository on practices. Its Dangerous-Workflow, Token-Permissions and Pinned-Dependencies checks apply here. | Posture reporting |
| CodeQL | Query-based analysis with a language called `actions`. It includes queries for code injection and untrusted checkout. | Findings in the code scanning UI |
These tools overlap but do not match exactly. Each has its own rules, severities and blind spots, so running two of them catches more than running one.
A workflow to audit
Save this as .github/workflows/triage.yml in a scratch repository. It combines three problems from earlier chapters.
name: triage
on:
pull_request_target:
types: [opened]
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: echo "Reviewing ${{ github.event.pull_request.title }}"
- run: npm ci && npm testThe problems are:
- The
pull_request_targettrigger gives the job a privileged token and secrets. - The checkout fetches fork code, and
npm ci && npm testthen runs it (a pwn request). - The PR title is expanded into the shell script (script injection).
Running zizmor
Install it with any of these commands:
pipx install zizmor
brew install zizmor
cargo install --locked zizmorRun it against the repository root or a specific directory:
zizmor .
zizmor .github/workflows/Zizmor prints one finding per problem, each with a rule name, a severity, and the file location with a snippet. The output below shows the general shape and is abbreviated. Exact wording and severities vary by version.
error[dangerous-triggers]: use of fundamentally insecure workflow trigger
--> .github/workflows/triage.yml:2:1
|
2 | on:
| ^^ pull_request_target is almost always used insecurely
error[template-injection]: code injection via template expansion
--> .github/workflows/triage.yml:11:13
|
11 | - run: echo "Reviewing ${{ github.event.pull_request.title }}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ may expand into attacker-controllable codeZizmor may also report missing permissions: as excessive-permissions, and it may report the tag-based actions/checkout@v4 reference as unpinned.
Useful options:
zizmor --format sarif . > results.sarif
zizmor --persona auditor .
zizmor --min-severity medium .--format sarifproduces output that GitHub code scanning can ingest.--personachanges how aggressive the checks are. Theauditorpersona reports more, including lower-confidence findings.--min-severityhides low-severity findings so a first run is not overwhelming.
Zizmor exits with a nonzero status when it reports findings, which makes it usable as a CI gate.
Running actionlint
actionlintWith no arguments, actionlint checks every workflow under .github/workflows. For our file, it reports the title expression as potentially untrusted and recommends passing it through an environment variable. This is the fix from the earlier chapter on environment variables. Actionlint does not reason as deeply about trigger risk as zizmor does. Its strength is catching many ordinary mistakes, such as wrong expression types, unknown contexts and bad needs: references, so it works well as a first pass.
Fixing the findings
Apply the patterns from earlier chapters:
name: triage
on:
pull_request:
types: [opened]
permissions:
contents: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: echo "Reviewing $PR_TITLE"
- run: npm ci && npm testThe trigger is now pull_request, so fork code runs with a read-only token and no secrets. The checkout no longer points at the PR head explicitly. The title travels in an environment variable. Permissions are explicit. Run both tools again and confirm the findings are gone.
If you do need a privileged step, such as posting a comment, split it into a separate workflow_run workflow that does not execute PR code. Treat any artifacts it downloads as untrusted.
Running the audit in CI
An audit that only runs on a developer's laptop will be skipped. Put it in a workflow that runs on every pull request. This workflow is itself safe: it uses the unprivileged pull_request trigger, a read-only token, and no secrets.
name: audit-workflows
on:
pull_request:
paths:
- ".github/workflows/**"
permissions:
contents: read
jobs:
zizmor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- run: pipx run zizmor .github/workflowsSetting persist-credentials: false stops the checkout from leaving the token in the local Git configuration, where later steps could read it. Zizmor has an audit for that pattern too. The paths filter limits the job to pull requests that change workflow files.
If you want results in the Security tab, upload SARIF with github/codeql-action/upload-sarif. That upload needs the security-events: write permission. Fork pull requests get a read-only token, so the upload step will fail for them. A common design is to run the blocking check on pull_request and upload SARIF only from pushes to the default branch.
Triage and limits
Static tools make mistakes in both directions, so treat each finding as a question to answer:
- False positives. A tool may flag
${{ github.event.issue.number }}even though the value is a number the attacker cannot shape. Check what type of value the expression produces. If the finding is safe, suppress that one finding with the tool's ignore mechanism and leave a comment explaining why. Do not turn the rule off globally. - False negatives. A tool cannot see inside a composite action's logic unless it is in the repository, and it cannot see what a reusable workflow does with inputs you pass from elsewhere. It also cannot tell whether a script file that a
run:step calls is safe. Manually review any step that executes code from a checkout. - Severity is not exploitability. A
pull_request_targetfinding in a workflow that never checks out PR code and never interpolates event data is much lower risk than the same finding next to a head-SHA checkout. Read the whole job before deciding. - Tools lag behind new attack patterns. Update them regularly, and pair them with the repository settings from the fork approval chapter.
Making it a habit
- Run actionlint and zizmor as pre-commit hooks or in an editor integration so mistakes surface while writing.
- Make the CI audit a required status check on the default branch.
- Add a scheduled run (for example weekly) so new rules apply to old workflows.
- Scan every repository in an organization at least once, since forgotten repositories often hold the oldest and riskiest workflows.
Exercise
A teammate says, "zizmor flagged ${{ github.event.pull_request.number }} in a run step, so we should disable the template-injection rule." What do you recommend instead?
Show answer
Check what the expression produces. A pull request number is an integer assigned by GitHub, so the attacker cannot inject shell syntax through it, and this is likely a low-risk finding. Suppress or ignore that single finding with a comment explaining why, or pass the value through an environment variable to silence it cleanly. Keep the rule enabled, because it still catches dangerous values such as titles, branch names and comment bodies.
Exercise
You add a workflow that runs zizmor on pull_request and uploads the SARIF file to code scanning. Pull requests from forks fail at the upload step. Why, and how can you fix it?
Show answer
Fork pull requests run with a read-only GITHUBTOKEN, and uploading SARIF needs the security-events: write permission. Keep the blocking check on `pullrequest using the exit code of zizmor, and run the SARIF upload only on pushes to the default branch or on a schedule. Do not switch to pullrequesttarget` to get write access, because that would reintroduce the risk of running untrusted code with privileges.