// guides

GitHub Actions Security: Attack Paths You Can Test

GitHub Actions security diagram of a CI runner reaching production cloud credentials

GitHub Actions security fails when a workflow treats a pull request, a cache or a third-party action as trusted code that can mint cloud credentials. Each of those paths is testable. Fork the repo, reach the point where untrusted input meets privileged code, and record whether a secret, an OIDC role or runner state moves.

The short answer

  • GitHub Actions security is the workflow itself: pull_request_target, workflow_run, untrusted run contexts, wide OIDC subjects, and persistent runners or caches.
  • A fork pull_request is secretless and read-only. pull_request_target and workflow_run run in the base repo and can reach production credentials if they execute PR code.
  • Prove each path with an authorized marker. Fix permissions and OIDC subjects first, then move to ephemeral runners and SHA pins.

GitHub Actions security concept of pipeline keys moving into production
Workflow credentials are production credentials.

Key takeaways

  • pull_request_target, workflow_run and issue_comment run with secrets; checking out and executing PR code there is a pwn request.
  • Untrusted contexts such as titles, bodies and branch names become shell code when interpolated into run: steps; pass them through environment variables instead.
  • An OIDC trust policy of repo:org/* or repo:org/repo:* hands cloud roles to unreviewed refs; scope it to a branch or environment and check aud.
  • Long-lived self-hosted runners, shared caches and workflow_run artifacts carry attacker state into privileged jobs.
  • SHA pinning stops retag attacks like CVE-2025-30066 but does not review new pins or block runtime egress.
  • Every path has a safe marker-based test case the platform team can rerun after each fix.

Why does GitHub Actions security start with the workflow file?

A GitHub Actions job is a short-lived identity with long-lived authority. It can hold cloud roles, container registry tokens, deploy keys, signing keys, and a GITHUB_TOKEN that can push to the default branch.

Perimeter and web tests rarely open the file that grants all of that. The workflow YAML decides the trigger, the token scopes, which commit gets checked out, and which OIDC subject claim the job may present to cloud providers. OWASP’s Top 10 CI/CD Security Risks names the core failure Poisoned Pipeline Execution (CICD-SEC-4).

In a typical organization’s repos, a job can call AWS STS AssumeRoleWithWebIdentity, GCP Workload Identity Federation, Azure federated credentials or Vault JWT auth, then push an image or a package. In December 2024, a compromised Actions workflow in the ultralytics project published malicious package versions to PyPI.

Observed incidents map to MITRE ATT&CK: supply-chain compromise (T1195), unsecured credentials (T1552), valid accounts (T1078) and command and scripting interpreter abuse (T1059). Treat the workflow definition as production code. A secure code review of workflow definitions belongs in the same queue as application changes, with the same required reviewers.

What is the difference between pull_request and pull_request_target?

A pull_request workflow triggered from a fork runs with a read-only GITHUB_TOKEN and no repository secrets. pull_request_target runs in the base repository, with secrets and a token that is often write-scoped. Checking out and executing the PR head there is what GitHub Security Lab calls a pwn request: a privileged trigger, a checkout of untrusted code, and anything that executes it.

GitHub added pull_request_target so maintainers could label or comment on fork PRs without running their code, and actions/checkout under that trigger fetches the base branch by default. The break in the boundary is an explicit ref: pointing checkout at github.event.pull_request.head.sha (or head.ref).

After that, npm ci, pip install -e ., make, a linter, a formatter or a test runner executes the fork author’s tree. Lifecycle scripts and git hooks in that tree run with the job’s secrets.

Trigger Secrets GITHUB_TOKEN Who can fire it
pull_request from a fork Withheld Read-only Anyone who can open a PR
pull_request_target Available Base-repo token, often write Anyone who can open a PR
workflow_run Available Default-branch context; scopes come from that workflow’s own permissions: block Any workflow it watches, including fork PR workflows
issue_comment Available Base-repo context Anyone who can comment, if the if: filter is loose

workflow_run and issue_comment sit in the same risk class and are often wired to an artifact download or a checkout of github.event.workflow_run.head_branch. Grep the workflow files for all three trigger names. A repo that retired pull_request_target but kept workflow_run has moved where untrusted input reaches privileged code. It has not closed the path.

When is pull_request_target safe?

It is safe when the job never checks out or executes PR-controlled files and never treats PR text as code. Rank the usage patterns by residual risk:

  • Lowest: label, comment or set a status from the event payload only. No checkout, no script that interpolates title, body or branch name.
  • Acceptable when reviewed: check out the base ref and run scripts that already live on the default branch.
  • Highest: a checkout of the head SHA followed by any install or test step, or a two-workflow split that still feeds a fork artifact into a secret-bearing job.

To test, use a repo created for the engagement. Open a PR that adds a harmless install hook writing a unique marker to the job log, and point the privileged workflow at the head SHA. If the marker appears in a job holding secrets or id-token: write, the path is exploitable. Record the run URL, the checked-out ref and the permissions: block. Never exfiltrate a live secret to prove it.

Blocking the trigger org-wide breaks maintainer automation and pushes teams toward workflow_run, which keeps secrets and adds an artifact handoff. Teach the no-checkout pattern and enforce it in review instead.

pull_request versus pull_request_target shown as a closed gate and an open vault
Same pull request, different token and secret access.

Which contexts cause GitHub Actions script injection, and how do you stop it?

Any context an external user can set becomes shell code when a workflow interpolates it with ${{ }} inside a run: step. GitHub’s “Security hardening for GitHub Actions” guide lists the values that must stay out of script bodies.

That list includes github.event.issue.title and body; github.event.pull_request.title, body and head.ref; github.event.comment.body; github.event.review.body; github.event.pages.*.page_name; github.head_ref; commit messages; and author name or email. Branch names count: an attacker chooses them freely.

The expression is evaluated before the shell starts. A step that echoes an issue title inside quotes becomes the opening quote, the attacker’s text, then the closing quote, and the shell parses whatever landed in between. The injection fires on PR open or synchronize, before a human reviews the diff, so “we only deploy from main” offers no protection.

Two file channels carry the same bug beyond a single step. GITHUB_ENV, GITHUB_OUTPUT and GITHUB_PATH are files the runner reads for later steps. Attacker text written into GITHUB_ENV sets variables for the rest of the job; text written into GITHUB_PATH prepends directories to PATH.

CVE-2020-15228 covered the older set-env and add-path workflow commands, which GitHub disabled in late 2020 in favor of these files. The files remain an injection point whenever a workflow writes them from an untrusted context.

The fix is data passing, not escaping. Map the value into an environment variable (env: TITLE set from the expression) and reference “$TITLE” in the script, or pass it as an input to actions/github-script. The shell then receives data, not syntax. Benign test: open an issue whose title holds a shell metacharacter and a marker word. If the marker executes, the step is injectable.

Token scope limits blast radius when injection still lands. GITHUB_TOKEN defaults vary with repository settings and creation date, so verify each repo. Set permissions: contents: read at workflow level and widen only the job that needs more.

actions/checkout defaults persist-credentials to true and writes the token into .git/config, where any later install script can read it. Set persist-credentials: false on jobs that build untrusted trees. ::add-mask:: only redacts exact strings in logs; it does nothing against egress or encoded leaks.

Can a fork pull request mint a cloud credential through OIDC?

Yes, if the job has permissions: id-token: write and the cloud trust policy accepts the subject that run receives. The trust policy is the real control: whoever satisfies it can mint the credential.

GitHub issues a short-lived JWT that AWS, GCP Workload Identity Federation, Azure federated identity credentials and Vault validate. For a branch push the sub claim looks like repo:owner/repo:ref:refs/heads/branch; with an environment attached, repo:owner/repo:environment:name. pull_request events get a pull-request form of sub.

The sub claim for pull_request_target is the one to measure rather than assume: it runs in the base context, so it can resemble a base-branch subject. Print the claims from an authorized test workflow and bind the policy to the value you observed. Check aud too; for AWS it is typically sts.amazonaws.com, and a policy without an audience condition accepts tokens minted for another relying party.

Subject condition Who gets the role Operational cost
repo:org/* Every repo and ref in the org Lowest friction, widest blast radius
repo:org/repo:* Every ref of one repo, including feature branches Still includes unreviewed code
repo:org/repo:ref:refs/heads/main That branch only Deploy-from-tag needs explicit refs
repo:org/repo:environment:prod Jobs that attach the prod environment Best fit when environment reviewers gate the job

Test by decoding the token payload in a throwaway workflow and comparing sub and aud with the live IAM, Workload Identity or federated-credential condition. Attempt AssumeRole only against a role created for the test, with no data-plane permissions. Pair the review with AWS penetration testing of OIDC trust so CloudTrail, not just the YAML, shows which refs assumed the role.

GitHub Actions OIDC token visualized as a badge becoming a cloud key
A wide OIDC subject turns a CI job into a cloud role.

Where does attacker state survive: runners, caches and artifacts

Self-hosted runners, shared caches and workflow artifacts all let one job’s output become another job’s input. GitHub’s own guidance is not to use self-hosted runners on public repositories, because a fork PR that reaches an executing workflow runs on a machine that keeps state after the job ends.

The same residue affects private repos with external contributors and runners shared through org or enterprise runner groups. What survives a job on a long-lived runner:

  • The _work directory, including _work/_actions, where cached action code is not re-verified on every run.
  • _work/_tool, _diag logs, and the runner account’s shell profiles, cron entries and systemd units.
  • PATH entries and any binary dropped earlier.

GitHub-hosted runners get a fresh VM per job. Actions Runner Controller can provide ephemeral pods on Kubernetes, but a persistent volume, a privileged pod or a shared node cache can reintroduce persistence if configured that way. Kubernetes penetration testing for ephemeral runners should check the runner namespace, its service account and whether a second job sees the first job’s filesystem.

Runner test: on a dedicated runner, job A writes a marker under _work and in the runner user’s home. Run job B from another branch, then from another repo in the same group. If B can read the marker, jobs on this runner share state; if B came from a different repo, the runner group leaks state across repositories. Remove the marker afterwards.

Caches follow the same logic. actions/cache restores entries from the current branch, the base branch and the default branch. Risk is highest when:

  • the key derives from PR-controlled input, such as a lockfile hash, branch name or version string;
  • restore-keys use a broad shared prefix that collides across branches;
  • a later privileged job restores node_modules, build output or a tool binary and executes it.

Branch scoping stops most cross-branch restores, but not every collision. Record the save key, the restore key that hit and the branch that created the entry, and file a privileged restore of PR-controlled content as a finding.

Artifact poisoning is the cleaner path. An untrusted workflow calls actions/upload-artifact; a workflow_run job with secrets calls actions/download-artifact, then unzips, installs or publishes. That is Poisoned Pipeline Execution delivered as a file rather than a checkout ref. Prove it with an artifact containing only a marker, and fail the privileged job if the marker arrives.

Does SHA pinning stop a tj-actions-style compromise?

It stops the retag. A full 40-character commit SHA is immutable; @v4 and @main are not, and a moved tag is how a compromised action starts running inside your jobs.

CVE-2025-30066 is the March 2025 tj-actions/changed-files compromise, in which the action dumped CI secrets into workflow logs. Public reporting put the number of repositories using it at more than 23,000. CVE-2025-30154 covers the related reviewdog/action-setup compromise. Both made the case for SHA pins plus egress control.

Pinning does not review the next SHA you pin, and it does not stop a pinned action from calling out at runtime. Dependabot and Renovate can open SHA-bump PRs, which keeps upkeep low. GitHub offers an organization policy to require SHA pinning; confirm it is enabled on your plan and covers reusable workflows, not only step uses: lines.

Combine pins with a supply-chain audit of third-party actions: who publishes them, which token scopes they request and which hosts they call.

On tooling: actionlint is a fast syntax and expression linter. zizmor, octoscan (Synacktiv), poutine (BoostSecurity) and CodeQL flag dangerous triggers and untrusted checkouts. OpenSSF Scorecard’s Dangerous-Workflow and Pinned-Dependencies checks are a cheap first signal. StepSecurity’s Harden-Runner watches runtime egress. None of them reads your cloud trust policy, and none replaces reading the privileged workflows.

What does a GitHub Actions penetration test actually run?

A CI/CD penetration test inventories triggers, permissions, OIDC subjects, runners, caches and artifacts, then proves each path with a marker on an authorized copy of the pipeline.

Scope it with the platform team before any fork: target repos, whether self-hosted runners are in bounds, which cloud account hosts test roles, and a rule that live production secrets never leave the runner. Evidence is the run URL, workflow SHA, permissions: block, decoded OIDC sub, runner hostname and cache or artifact name.

Path Test case Fix
Pwn request Fork PR with an install-hook marker reaches a secret-bearing job No PR-head checkout under pull_request_target, workflow_run or issue_comment
Script injection Title or branch name with a metacharacter and marker Env-var or github-script input; contents: read token
OIDC trust Decode sub and aud, compare with the live policy Ref- or environment-scoped subject plus aud condition
Runner persistence Job A marker read by job B from another repo Ephemeral runners; no self-hosted runners on public repos
Cache or artifact poisoning Marker cache entry or artifact restored in a privileged job Trusted keys; no fork artifacts in secret-bearing jobs
Mutable action ref List tag and branch pins in privileged workflows Full SHA pins plus egress allow-lists

Week one, in order:

  • Set workflow-level permissions to contents: read and widen only the job that needs more. Keep id-token: write only where the trust policy is ref- or environment-scoped.
  • Rewrite pull_request_target, workflow_run and issue_comment jobs so they never execute PR heads or fork artifacts.
  • Replace tag pins with SHAs on privileged workflows.
  • Set persist-credentials: false on untrusted checkouts.

Architecture work follows: ephemeral runners, environment reviewers on prod subjects, the org SHA-pin policy and egress allow-lists. A policy PDF that does not change the YAML will be overwritten by the next scaffolded workflow.

To catch abuse in progress, alert on AssumeRoleWithWebIdentity events in CloudTrail whose sub is not a protected branch or environment, fork-PR runs of privileged workflows, unexpected outbound hosts from runners, and new files in self-hosted runner directories between jobs.

Report findings to AppSec and to the runner owners. AppSec owns injection and pwn-request diffs; platform owns runner groups, cache scope and cloud subjects. File with both teams, or the fix stalls.

FAQ

Is pull_request_target always insecure?

No. It is safe when the job uses only the event payload or base-branch scripts and never checks out or executes PR-controlled files. Risk starts the moment a ref: points checkout at the PR head and any install, build or test step runs.

How do I prevent script injection in GitHub Actions?

Never place ${{ }} expressions for attacker-controlled fields inside run: scripts. Assign them to an environment variable and reference the variable in the shell, or pass them as inputs to actions/github-script. Also restrict GITHUB_TOKEN to contents: read.

Can a fork pull request get an AWS role through GitHub OIDC?

It can if the job has id-token: write and the role's trust policy accepts the subject the run presents. Wildcard subjects like repo:org/* are the usual cause. Decode the token in a test workflow and compare sub and aud against the live policy.

Are self-hosted runners safe for public repositories?

GitHub advises against it. A fork PR that reaches an executing workflow runs on a machine that keeps files, tools and profiles between jobs. Use GitHub-hosted runners or truly single-use ephemeral runners for untrusted code.

Does pinning actions to a commit SHA stop a tj-actions-style attack?

It stops a moved tag from changing code you already approved. It does not vet the next SHA you pin or stop a pinned action from making network calls, so pair pins with supply-chain review and egress allow-lists.

agent::offense tests GitHub Actions the way an attacker walks them: privileged triggers, OIDC subjects, runner residue, and cache or artifact handoffs, with proof your platform team can rerun. See secure code review for workflow diffs, or scope a pipeline engagement alongside cloud and runner tests.



// get started

Work with AgentOffense

Tell us about your target and goals. We’ll reply with scope and a fixed-price quote — usually within one business day.

./request_engagement