Sub topic 15
Auditing workflows with automated tools
You have seen the patterns that make workflows exploitable. This chapter shows how to find them automatically. It assumes you can read the vulnerable and fixed examples from earlier chapters and can run commands in a terminal.
Why audit with tools
Reviewing every workflow by hand does not scale, and a small edit can reintroduce a fixed bug. Static analyzers read the workflow YAML and flag known risky shapes. They do not run the workflow, so they are cheap to run on every pull request.
Each tool covers a different slice of the problem:
| Tool | What it checks | Typical use |
|---|---|---|
| zizmor | Template injection, dangerous triggers, excessive permissions, unpinned actions | Security-focused audit of workflow files |
| actionlint | Syntax and type errors, plus a check for untrusted inputs in expressions | General linting that also catches some injection |
| CodeQL for Actions | Code injection and untrusted checkout, using data-flow queries | Code scanning in GitHub's Security tab |
| Harden-Runner | Network and process behavior while the job runs | Runtime monitoring, not a static check |
Running zizmor locally
zizmor targets the weaknesses in this tutorial. Its template-injection audit finds ${{ }} expressions placed in run steps or github-script code. Its dangerous-triggers audit reports pull_request_target and similar events. Its excessive-permissions audit reports broad token scopes. Install it and point it at your workflows:
pip install zizmor
zizmor .github/workflows/Each finding names the audit, the file and line, and a severity. Run it against the vulnerable greet workflow from earlier. It should report a template injection on the github.event.issue.title expression. After you move the value into env:, that finding should disappear.
Running actionlint
actionlint catches mistakes such as wrong event names, bad expression types and invalid needs references. It also warns when a step interpolates a property that an outsider can control, such as a PR title or branch name. If shellcheck is installed, it checks the shell in run steps too.
actionlintRun it from the repository root. It finds .github/workflows by itself.
Auditing in CI
Run the audit as a workflow so new problems are caught before merge. This workflow uses the safe pull_request trigger, read-only permissions 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: pip install zizmor
- run: zizmor .github/workflows/The job fails when zizmor reports findings, so the check blocks the merge. The persist-credentials: false setting stops checkout from leaving the token in the local git config, where later steps could read it.
A workflow for triage
Triage by severity and reachability. A pull_request_target workflow that checks out fork code needs attention before a style warning does. An expression like ${{ github.sha }} is not attacker-controlled, so a finding on it is usually a false positive. Record why you ignored it, so the next reviewer does not repeat the analysis.
Limits of automated checks
- Static tools match patterns. They can miss injection that passes through a script file, a reusable workflow or an artifact.
- They cannot judge intent. A workflow that safely checks out fork code in an unprivileged job looks similar to a dangerous one.
- A clean report does not prove safety. Pair the tools with the design rules from earlier chapters: least-privilege tokens, split workflows and pinned actions.
Exercise
You run zizmor on a workflow and it reports a template injection on run: echo "${{ github.event.pull_request.title }}". What is the fix, and which two things would you check afterward?
Show answer
Pass the title through an environment variable (env: PR_TITLE: ${{ github.event.pull_request.title }}) and use "$PR_TITLE" in the script. Then rerun zizmor to confirm the finding is gone, and check that the workflow's permissions block is least-privilege in case another step is still exploitable.