
Locking Down GitHub Actions: Common Holes and Fixes
GitHub Actions security hardening explained with real workflow examples, from pinning actions to secrets scoping and preventing supply chain attacks.
Most CI/CD breaches don't start with a stolen laptop or a cracked password. They start with a misconfigured workflow file sitting quietly in a .github/workflows folder. If you ship code through GitHub Actions, that folder is part of your attack surface, whether you treat it that way or not.
Here's what actually goes wrong in the wild, and how to fix it.
Why GitHub Actions Is a Target
Actions run with access to your repo, your secrets, and sometimes your production deploy keys. A compromised workflow can:
- Exfiltrate secrets (API keys, cloud credentials, npm tokens) to an external server
- Push malicious commits or tags that look legitimate
- Modify release artifacts before they're published
- Pivot into connected infrastructure (AWS, npm, Docker Hub)
The 2021 Codecov breach and the 2023 attacks on third-party GitHub Actions (like tj-actions/changed-files) both showed how a single compromised dependency in a workflow can ripple across thousands of repos. This isn't theoretical.
Pin Every Action to a Commit SHA
This is the single highest-impact fix and the most commonly skipped one.
When you write:
uses: actions/checkout@v4
you're trusting that the tag v4 always points to the same safe code. But tags are mutable. If an attacker compromises the action's repo, they can move the v4 tag to point at malicious code, and every workflow referencing it silently pulls the new version on the next run.
Instead, pin to the full commit SHA:
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe8273 # v4.1.1
Yes, it's uglier. Yes, you should do it for every third-party action, not just your own org's. Tools like Dependabot can keep pinned SHAs updated automatically, so this isn't a maintenance burden once it's set up.
Quick checklist
- Audit every
uses:line across your workflows - Replace version tags with full-length commit SHAs
- Add a comment with the human-readable version for clarity
- Enable Dependabot version updates for GitHub Actions in
dependabot.yml
Scope Your Permissions Down to Nothing
By default, the GITHUB_TOKEN used in workflows often has broad read/write access to the repository. Most jobs don't need that.
Set a restrictive default at the top of your workflow file:
permissions:
contents: read
Then grant specific permissions only to the jobs that need them:
jobs:
release:
permissions:
contents: write
id-token: write
This limits blast radius. If a step in your test job gets compromised through a malicious dependency, it can't push tags, open PRs, or write packages, because it was never given that permission in the first place.
Stop Trusting pull_request_target Blindly
The pull_request_target trigger runs with access to your repo's secrets, even for PRs from forks. This is useful for things like commenting on PRs automatically, but it's a well-known attack vector.
If you combine pull_request_target with checking out the PR's head ref and then running that code, you've handed an attacker a path to execute arbitrary code with your secrets:
# Dangerous pattern, avoid this
on: pull_request_target
jobs:
build:
steps:
- uses: actions/checkout@SHA
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm install && npm test
If you need to run code from forked PRs, use the regular pull_request trigger (which runs with no access to secrets) and a separate, carefully scoped workflow for anything that needs write access.
Secrets Hygiene That Actually Matters
- Use environment-scoped secrets instead of repo-wide secrets. A secret only available to the "production" environment can't be read by a PR workflow.
- Require reviewers on protected environments so deploys to production need manual approval, adding a human checkpoint before secrets are used.
- Rotate long-lived credentials. If you're still using static AWS keys in GitHub secrets, switch to OpenID Connect (OIDC) so GitHub Actions requests short-lived tokens directly from AWS, Azure, or GCP. No long-lived secret sitting in your repo settings at all.
- Never echo secrets to logs, even for debugging. GitHub masks exact string matches, but transformed or partially masked secrets (base64-encoded, split across variables) can leak in plain text.
Audit Third-Party Actions Before You Add Them
Before pulling in a new action from the marketplace, check:
- Is the source code actually readable, or just a compiled
dist/index.js? - Does the repo have recent commits and an active maintainer?
- Does it request more permissions than its stated purpose needs?
- Is there a verified publisher badge?
If an action only needs to read repo metadata but asks for write access to packages or deployments, that's a red flag worth investigating further.
Harden Self-Hosted Runners Separately
Self-hosted runners introduce a different risk profile than GitHub's ephemeral cloud runners. If you're running your own:
- Never use self-hosted runners for public repositories. A malicious PR can execute arbitrary code on your infrastructure.
- Use ephemeral, single-job runners that are destroyed after each run rather than persistent VMs that accumulate state.
- Isolate runners on their own network segment, away from production systems.
Where This Connects to Your Web Security Posture
Hardening your CI/CD pipeline is only half the picture. A compromised workflow is often the entry point, but the real damage shows up on the live site: injected scripts, weakened CSP headers, exposed cookies without proper flags, or a certificate quietly expiring because a deploy failed silently. This is where it pays to check the output, not just the input.
Running a scan with WebSentry after deployments gives you a clear A-F grade across SSL/TLS configuration, security headers, CSP, cookie flags, DNS records, and CORS policy, so you can catch the downstream effects of a pipeline issue before an attacker does. Teams that ship through Actions multiple times a day benefit from treating a WebSentry scan like a smoke test: if a deploy quietly drops your HSTS header or opens up a permissive CORS policy, you'll know within minutes instead of finding out from a security researcher's email.
It's also worth running WebSentry against staging environments connected to your CI pipeline. Misconfigured headers or exposed debug endpoints often get pushed to staging first, and catching them there is a lot cheaper than catching them in production.
A Minimal Hardening Checklist to Start Today
- Pin all actions to commit SHAs, not tags
- Set
permissions: read-allor stricter as the workflow default - Replace
pull_request_target+ code checkout patterns with safer alternatives - Move cloud credentials to OIDC instead of static secrets
- Require approval for deployments to protected environments
- Audit third-party actions quarterly
- Scan your live site with WebSentry after major pipeline changes to confirm nothing broke silently
Go run a free scan at websentry.dev and see what your current deploy pipeline is actually shipping to production.
Check your own site
Run a free security scan and see if your site has the issues covered in this article. Results in under 30 seconds.